sharepoint_api 1.0.1 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.pryrc +46 -0
- data/CHANGELOG.md +19 -3
- data/Gemfile +7 -2
- data/Gemfile.lock +54 -7
- data/Guardfile +42 -0
- data/README.md +7 -5
- data/bin/console +4 -4
- data/docs/pull_request_template.md +38 -0
- data/lib/sharepoint_api.rb +4 -4
- data/lib/sharepoint_api/file_info.rb +49 -2
- data/lib/sharepoint_api/file_system.rb +30 -24
- data/lib/sharepoint_api/permissions.rb +9 -2
- data/lib/sharepoint_api/version.rb +1 -1
- data/sharepoint_api.gemspec +3 -3
- metadata +16 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eac6402d99bf11213a9a8edc411745d2056ec8ffd3846f5579b91e3383709515
|
4
|
+
data.tar.gz: ef5281daee7e600d3a67a480c561e76779eff8fcb4e8bec8005894500dc43361
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f3a17b7be2e3a31b9d45f26d407750979d6d2d9946e5b5c46030eb9d49f06a3c02557bcfc926ddb6277828fe962920780d9cca5dc67465b6bea5267ec27c113
|
7
|
+
data.tar.gz: ce320268dcc75d3348bab171a58874e075590bbb2a2e2e49c86a05d6bcbaea1568b3f832732506fe9c17f35fefb7ffbf99705c509e63079070dbd6f6538f2c9c
|
data/.pryrc
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
#!/usr/env/bin ruby
|
2
|
+
|
3
|
+
# user = `echo "$USER"`.strip
|
4
|
+
class ProgrammerError < StandardError; end
|
5
|
+
|
6
|
+
if defined?(Pry)
|
7
|
+
Pry.config.editor = 'vim'
|
8
|
+
|
9
|
+
# Hit enter to repeat the last command.
|
10
|
+
Pry::Commands.command(/^$/, 'Repeat last command.') do
|
11
|
+
pry_instance.run_command Pry.history.to_a.last
|
12
|
+
end
|
13
|
+
|
14
|
+
Pry::Commands.command('args', 'Display local variables.') do
|
15
|
+
pry_instance.run_command 'ls -l'
|
16
|
+
end
|
17
|
+
|
18
|
+
Pry.commands.alias_command 'ss', 'show-source'
|
19
|
+
Pry.commands.alias_command 'q', 'quit'
|
20
|
+
Pry.commands.alias_command 'w', 'whereami'
|
21
|
+
Pry.commands.alias_command 'r', 'reload-code'
|
22
|
+
Pry.commands.alias_command 'ed', 'edit'
|
23
|
+
Pry.commands.alias_command 'ec', 'edit -c' # open current file in editor
|
24
|
+
end
|
25
|
+
|
26
|
+
if defined?(PryByebug)
|
27
|
+
Pry.commands.alias_command 'b', 'backtrace'
|
28
|
+
Pry.commands.alias_command 'c', 'continue'
|
29
|
+
Pry.commands.alias_command 'n', 'next'
|
30
|
+
Pry.commands.alias_command 's', 'step'
|
31
|
+
end
|
32
|
+
|
33
|
+
class String
|
34
|
+
def gitize
|
35
|
+
gsub(/\W+$/, ''). # kill trailing whitespace
|
36
|
+
gsub(/\W+/, '-'). # replace whitespace with -
|
37
|
+
gsub(/([A-Z])/, '-\1'). # prepend dash to capitals
|
38
|
+
gsub(/^-/, ''). # strip leading dash
|
39
|
+
gsub(/-+/, '-'). # compress multiple dashes to a single dash
|
40
|
+
downcase
|
41
|
+
end
|
42
|
+
|
43
|
+
def prize
|
44
|
+
gsub(/\W+$/, '').gsub(/\W+/, ' ').gsub(/\b(?<!['’`])[a-z]/, &:capitalize)
|
45
|
+
end
|
46
|
+
end
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,21 @@
|
|
1
|
-
## [
|
2
|
-
*
|
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
|
+
|
11
|
+
## [1.0.3] - 2021-01-12
|
12
|
+
* Handle edge case where FileInfo file#modified_by refers to a user that no longer exists.
|
13
|
+
|
14
|
+
## [1.0.2] - 2021-01-04
|
15
|
+
* Handle edge case where FileInfo file/file version refers to a user that no longer exists.
|
3
16
|
|
4
17
|
## [1.0.1] - 2020-12-14
|
5
|
-
* Added new method called fetch_role_assignments => allows a user to get all the current role assignments on a SharePoint folder
|
18
|
+
* Added new method called fetch_role_assignments => allows a user to get all the current role assignments on a SharePoint folder
|
19
|
+
|
20
|
+
## [1.0.0] - 2020-12-07
|
21
|
+
* Initial Release
|
data/Gemfile
CHANGED
@@ -5,9 +5,14 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
|
5
5
|
# Specify your gem's dependencies in sharepoint_api.gemspec
|
6
6
|
gemspec
|
7
7
|
|
8
|
-
gem 'faker'
|
8
|
+
gem 'faker', '~> 2.15'
|
9
|
+
gem 'guard', '~> 2.16'
|
10
|
+
gem 'guard-rspec', '~> 4.7'
|
11
|
+
gem 'pry', '~> 0.13.1'
|
12
|
+
gem 'pry-byebug', '~> 3.9'
|
13
|
+
gem 'pry-rescue', '~> 1.5'
|
9
14
|
gem 'rake', '~> 13.0'
|
10
15
|
gem 'rspec', '~> 3.6'
|
11
|
-
gem 'rspec-collection_matchers'
|
16
|
+
gem 'rspec-collection_matchers', '~> 1.2'
|
12
17
|
gem 'rubocop', '~> 1.5'
|
13
18
|
gem 'rubocop-rspec', '~> 2.0'
|
data/Gemfile.lock
CHANGED
@@ -1,31 +1,71 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
sharepoint_api (
|
4
|
+
sharepoint_api (2.2.0)
|
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
|
+
byebug (11.1.3)
|
15
|
+
coderay (1.1.3)
|
14
16
|
concurrent-ruby (1.1.7)
|
15
17
|
curb (0.9.10)
|
16
18
|
diff-lcs (1.4.4)
|
17
19
|
faker (2.15.1)
|
18
20
|
i18n (>= 1.6, < 2)
|
21
|
+
ffi (1.14.2)
|
22
|
+
formatador (0.2.5)
|
23
|
+
guard (2.16.2)
|
24
|
+
formatador (>= 0.2.4)
|
25
|
+
listen (>= 2.7, < 4.0)
|
26
|
+
lumberjack (>= 1.0.12, < 2.0)
|
27
|
+
nenv (~> 0.1)
|
28
|
+
notiffany (~> 0.0)
|
29
|
+
pry (>= 0.9.12)
|
30
|
+
shellany (~> 0.0)
|
31
|
+
thor (>= 0.18.1)
|
32
|
+
guard-compat (1.2.1)
|
33
|
+
guard-rspec (4.7.3)
|
34
|
+
guard (~> 2.1)
|
35
|
+
guard-compat (~> 1.1)
|
36
|
+
rspec (>= 2.99.0, < 4.0)
|
19
37
|
i18n (1.8.5)
|
20
38
|
concurrent-ruby (~> 1.0)
|
39
|
+
interception (0.5)
|
40
|
+
listen (3.4.0)
|
41
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
42
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
43
|
+
lumberjack (1.2.8)
|
44
|
+
method_source (1.0.0)
|
45
|
+
nenv (0.3.0)
|
46
|
+
notiffany (0.1.3)
|
47
|
+
nenv (~> 0.1)
|
48
|
+
shellany (~> 0.0)
|
21
49
|
parallel (1.20.1)
|
22
50
|
parser (2.7.2.0)
|
23
51
|
ast (~> 2.4.1)
|
24
|
-
proof-sharepoint-ruby (
|
52
|
+
proof-sharepoint-ruby (2.0.0)
|
25
53
|
curb (~> 0.8, <= 0.9.10)
|
54
|
+
pry (0.13.1)
|
55
|
+
coderay (~> 1.1)
|
56
|
+
method_source (~> 1.0)
|
57
|
+
pry-byebug (3.9.0)
|
58
|
+
byebug (~> 11.0)
|
59
|
+
pry (~> 0.13.0)
|
60
|
+
pry-rescue (1.5.2)
|
61
|
+
interception (>= 0.5)
|
62
|
+
pry (>= 0.12.0)
|
26
63
|
public_suffix (4.0.6)
|
27
64
|
rainbow (3.0.0)
|
28
65
|
rake (13.0.1)
|
66
|
+
rb-fsevent (0.10.4)
|
67
|
+
rb-inotify (0.10.1)
|
68
|
+
ffi (~> 1.0)
|
29
69
|
regexp_parser (2.0.0)
|
30
70
|
rexml (3.2.4)
|
31
71
|
rspec (3.10.0)
|
@@ -58,19 +98,26 @@ GEM
|
|
58
98
|
rubocop (~> 1.0)
|
59
99
|
rubocop-ast (>= 1.1.0)
|
60
100
|
ruby-progressbar (1.10.1)
|
101
|
+
shellany (0.0.1)
|
102
|
+
thor (1.0.1)
|
61
103
|
unicode-display_width (1.7.0)
|
62
104
|
|
63
105
|
PLATFORMS
|
64
106
|
ruby
|
65
107
|
|
66
108
|
DEPENDENCIES
|
67
|
-
faker
|
109
|
+
faker (~> 2.15)
|
110
|
+
guard (~> 2.16)
|
111
|
+
guard-rspec (~> 4.7)
|
112
|
+
pry (~> 0.13.1)
|
113
|
+
pry-byebug (~> 3.9)
|
114
|
+
pry-rescue (~> 1.5)
|
68
115
|
rake (~> 13.0)
|
69
116
|
rspec (~> 3.6)
|
70
|
-
rspec-collection_matchers
|
117
|
+
rspec-collection_matchers (~> 1.2)
|
71
118
|
rubocop (~> 1.5)
|
72
119
|
rubocop-rspec (~> 2.0)
|
73
120
|
sharepoint_api!
|
74
121
|
|
75
122
|
BUNDLED WITH
|
76
|
-
|
123
|
+
2.2.4
|
data/Guardfile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
## Uncomment and set this to only include directories you want to watch
|
5
|
+
# directories %w(app lib config test spec features) \
|
6
|
+
# .select{|d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist")}
|
7
|
+
|
8
|
+
## Note: if you are using the `directories` clause above and you are not
|
9
|
+
## watching the project directory ('.'), then you will want to move
|
10
|
+
## the Guardfile to a watched dir and symlink it back, e.g.
|
11
|
+
#
|
12
|
+
# $ mkdir config
|
13
|
+
# $ mv Guardfile config/
|
14
|
+
# $ ln -s config/Guardfile .
|
15
|
+
#
|
16
|
+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
17
|
+
|
18
|
+
# Note: The cmd option is now required due to the increasing number of ways
|
19
|
+
# rspec may be run, below are examples of the most common uses.
|
20
|
+
# * bundler: 'bundle exec rspec'
|
21
|
+
# * bundler binstubs: 'bin/rspec'
|
22
|
+
# * spring: 'bin/rspec' (This will use spring if running and you have
|
23
|
+
# installed the spring binstubs per the docs)
|
24
|
+
# * zeus: 'zeus rspec' (requires the server to be started separately)
|
25
|
+
# * 'just' rspec: 'rspec'
|
26
|
+
|
27
|
+
guard :rspec, cmd: 'echo -e "\033c"; bundle exec rspec' do
|
28
|
+
require 'guard/rspec/dsl'
|
29
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
30
|
+
|
31
|
+
# Feel free to open issues for suggestions and improvements
|
32
|
+
|
33
|
+
# RSpec files
|
34
|
+
rspec = dsl.rspec
|
35
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
36
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
37
|
+
watch(rspec.spec_files)
|
38
|
+
|
39
|
+
# Ruby files
|
40
|
+
ruby = dsl.ruby
|
41
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
42
|
+
end
|
data/README.md
CHANGED
@@ -39,25 +39,27 @@ api = SharepointApi.new(
|
|
39
39
|
|
40
40
|
api.fetch_content_types # or whatever method you want to test.
|
41
41
|
```
|
42
|
+
|
42
43
|
## Development
|
43
44
|
|
44
45
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
45
46
|
|
46
47
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
47
48
|
|
49
|
+
> NOTE: run `bundle install` and commit the changes to the Gemfile.lock before deploying a new version.
|
50
|
+
|
48
51
|
## Testing
|
49
52
|
|
50
|
-
|
51
|
-
`
|
53
|
+
Start the test suite watcher:
|
54
|
+
`bundle exec guard`
|
52
55
|
|
53
|
-
Run the tests for just one file
|
54
|
-
`
|
56
|
+
Run the tests for just one file just enter the filename in the Guard console.
|
57
|
+
`spec/sharepoint_api/items_spec.rb`
|
55
58
|
|
56
59
|
## Contributing
|
57
60
|
|
58
61
|
Bug reports and pull requests are welcome on GitHub at https://github.com/anlek/sharepoint_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/anlek/sharepoint_api/blob/master/CODE_OF_CONDUCT.md).
|
59
62
|
|
60
|
-
|
61
63
|
## License
|
62
64
|
|
63
65
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/bin/console
CHANGED
@@ -7,8 +7,8 @@ require "sharepoint_api"
|
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
8
8
|
|
9
9
|
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
|
11
|
-
|
10
|
+
require "pry"
|
11
|
+
Pry.start
|
12
12
|
|
13
|
-
require "irb"
|
14
|
-
IRB.start(__FILE__)
|
13
|
+
# require "irb"
|
14
|
+
# IRB.start(__FILE__)
|
@@ -0,0 +1,38 @@
|
|
1
|
+
[XXXXX](https://proof-tech.atlassian.net/browse/XXXXX)
|
2
|
+
|
3
|
+
### Overview
|
4
|
+
|
5
|
+
Please include a summary of the changes in this pull request.
|
6
|
+
List any dependencies that are required before this change is applied.
|
7
|
+
|
8
|
+
### Solution
|
9
|
+
|
10
|
+
How did you solve the problem?
|
11
|
+
Call out any particular implementation choices or design decisions you made
|
12
|
+
|
13
|
+
### Screenshots
|
14
|
+
|
15
|
+
[insert screenshots here]
|
16
|
+
|
17
|
+
### Testing Instructions
|
18
|
+
|
19
|
+
Describe, for your colleagues, how they can test your code locally on their system
|
20
|
+
|
21
|
+
### Pre-Merge Checklist
|
22
|
+
|
23
|
+
- [ ] I have updated the version and changelog in a different PR than bug fixes and features.
|
24
|
+
- [ ] The work here reflects the user stories in the JIRA ticket(s) listed at the top of this pull request
|
25
|
+
- [ ] This pull request has been referenced via URL in the JIRA ticket(s) listed
|
26
|
+
- [ ] I have performed a self-review of the code I have written here
|
27
|
+
- [ ] I have done end-to-end QA testing of sections of the code I have altered
|
28
|
+
- [ ] My changes generate no new warnings / errors in the console
|
29
|
+
- [ ] I have written/updated Ruby tests for the areas of the code base that I have modified
|
30
|
+
- [ ] I am prepared for this code to go to production today (or there is a WIP label on the pull request)
|
31
|
+
- [ ] I am prepared to write hotfixes or rollback my code if something goes wrong
|
32
|
+
|
33
|
+
### Gem Deployment Instructions
|
34
|
+
|
35
|
+
1. `bundle exec rake install`
|
36
|
+
2. `bundle exec rake release`
|
37
|
+
|
38
|
+
Reminder that deploy instructions are in the [here](https://github.com/proofgov/sharepoint_api#development).
|
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
|
@@ -1,5 +1,33 @@
|
|
1
|
+
require_relative 'sharepoint_error'
|
2
|
+
|
1
3
|
class SharepointApi
|
2
4
|
class FileInfo
|
5
|
+
class FileInfoError < SharepointError; end
|
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
|
+
].join(',')
|
18
|
+
"$select=Name,UpdatedAt,MajorVersion,TimeLastModified,#{sub_query}&$expand=#{sub_query}"
|
19
|
+
end.freeze
|
20
|
+
|
21
|
+
##
|
22
|
+
# Get just enough data to build a FileInfo object that suports to_h
|
23
|
+
FILE_SELECT_QUERY = begin
|
24
|
+
sub_query = %w[
|
25
|
+
ModifiedBy/LoginName
|
26
|
+
ListItemAllFields/Id
|
27
|
+
].join(',')
|
28
|
+
"$select=Name,UpdatedAt,MajorVersion,TimeLastModified,Versions,#{sub_query}&$expand=#{sub_query}"
|
29
|
+
end.freeze
|
30
|
+
|
3
31
|
extend Forwardable
|
4
32
|
attr_reader :version, :version_id, :file, :updated_at
|
5
33
|
|
@@ -31,7 +59,7 @@ class SharepointApi
|
|
31
59
|
version_id,
|
32
60
|
created_at: updated_at,
|
33
61
|
current: true,
|
34
|
-
creator_login: file
|
62
|
+
creator_login: safe_modified_by(file)&.login_name
|
35
63
|
)
|
36
64
|
|
37
65
|
return @all_versions unless version > 1
|
@@ -41,7 +69,7 @@ class SharepointApi
|
|
41
69
|
file_version.id,
|
42
70
|
created_at: Time.parse(file_version.created),
|
43
71
|
current: file_version.is_current_version,
|
44
|
-
creator_login: file_version
|
72
|
+
creator_login: safe_created_by(file_version)&.login_name
|
45
73
|
)
|
46
74
|
end
|
47
75
|
|
@@ -63,5 +91,24 @@ class SharepointApi
|
|
63
91
|
**attrs
|
64
92
|
)
|
65
93
|
end
|
94
|
+
|
95
|
+
def safe_modified_by(file)
|
96
|
+
file.modified_by
|
97
|
+
rescue Sharepoint::SPException => e
|
98
|
+
return nil if e.message =~ /User cannot be found/
|
99
|
+
|
100
|
+
raise(FileInfoError, e.message)
|
101
|
+
end
|
102
|
+
|
103
|
+
def safe_created_by(file_version)
|
104
|
+
return file_version.creator if file_version.data['CreatedBy']['__deferred']
|
105
|
+
return file_version.created_by if file_version.data['CreatedBy']['__metadata']
|
106
|
+
|
107
|
+
nil
|
108
|
+
rescue Sharepoint::SPException => e
|
109
|
+
return nil if e.message =~ /User cannot be found/
|
110
|
+
|
111
|
+
raise(FileInfoError, e.message)
|
112
|
+
end
|
66
113
|
end
|
67
114
|
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
|
@@ -97,14 +97,19 @@ class SharepointApi
|
|
97
97
|
false
|
98
98
|
end
|
99
99
|
|
100
|
-
def fetch_role_assignments(path)
|
100
|
+
def fetch_role_assignments(path, principal_id: nil)
|
101
101
|
server_path = server_relative_path(path)
|
102
102
|
list_item_path = "GetFolderByServerRelativeUrl('#{server_path}')/ListItemAllFields"
|
103
103
|
query = '$expand=Member,RoleDefinitionBindings&$select=RoleDefinitionBindings/Name&$select=RoleDefinitionBindings/Id,PrincipalId,Member/LoginName'
|
104
104
|
|
105
|
+
unless principal_id.nil?
|
106
|
+
principal_filter = encode_path("PrincipalId eq #{principal_id}")
|
107
|
+
query += "&$filter=#{principal_filter}"
|
108
|
+
end
|
109
|
+
|
105
110
|
response = site.query(:get, "#{list_item_path}/RoleAssignments?#{query}")
|
106
111
|
|
107
|
-
response.map do |assignment|
|
112
|
+
formatted = response.map do |assignment|
|
108
113
|
data = assignment.data
|
109
114
|
|
110
115
|
current_roles = data['RoleDefinitionBindings']['results'].map { |rdb| { role_id: rdb['Id'], role_name: rdb['Name'] } }
|
@@ -115,6 +120,8 @@ class SharepointApi
|
|
115
120
|
roles: current_roles
|
116
121
|
}
|
117
122
|
end
|
123
|
+
|
124
|
+
principal_id.nil? ? formatted : formatted.first
|
118
125
|
rescue Sharepoint::SPException => e
|
119
126
|
log_as(__method__, e)
|
120
127
|
false
|
data/sharepoint_api.gemspec
CHANGED
@@ -16,16 +16,16 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.metadata['source_code_uri'] = 'https://github.com/proofgov/sharepoint_api'
|
17
17
|
spec.metadata['changelog_uri'] = 'https://github.com/proofgov/sharepoint_api/blob/master/CHANGELOG.md'
|
18
18
|
|
19
|
-
spec.add_runtime_dependency('proof-sharepoint-ruby', '~> 1.0')
|
20
19
|
spec.add_runtime_dependency('addressable', '~> 2.7')
|
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.
|
24
24
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
25
25
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
26
|
end
|
27
|
-
spec.bindir = '
|
28
|
-
spec.executables = spec.files.grep(%r{^
|
27
|
+
spec.bindir = 'bin'
|
28
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
29
29
|
|
30
30
|
spec.require_paths = ['lib']
|
31
31
|
end
|
metadata
CHANGED
@@ -1,67 +1,72 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sharepoint_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kalek
|
8
8
|
- Marlen Brunner
|
9
9
|
- Danella Olsen
|
10
10
|
autorequire:
|
11
|
-
bindir:
|
11
|
+
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2021-07-07 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
16
|
+
name: addressable
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
18
|
requirements:
|
19
19
|
- - "~>"
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '
|
21
|
+
version: '2.7'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
26
|
- - "~>"
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version: '
|
28
|
+
version: '2.7'
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
|
-
name:
|
30
|
+
name: proof-sharepoint-ruby
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
33
|
- - "~>"
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version: '2.
|
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: '2.
|
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:
|
46
46
|
- akalek@proofgov.com
|
47
47
|
- mbrunner@proofgov.com
|
48
48
|
- dolsen@proofgov.com
|
49
|
-
executables:
|
49
|
+
executables:
|
50
|
+
- console
|
51
|
+
- setup
|
50
52
|
extensions: []
|
51
53
|
extra_rdoc_files: []
|
52
54
|
files:
|
53
55
|
- ".gitignore"
|
56
|
+
- ".pryrc"
|
54
57
|
- ".rspec"
|
55
58
|
- ".rubocop.yml"
|
56
59
|
- CHANGELOG.md
|
57
60
|
- CODE_OF_CONDUCT.md
|
58
61
|
- Gemfile
|
59
62
|
- Gemfile.lock
|
63
|
+
- Guardfile
|
60
64
|
- LICENSE.txt
|
61
65
|
- README.md
|
62
66
|
- Rakefile
|
63
67
|
- bin/console
|
64
68
|
- bin/setup
|
69
|
+
- docs/pull_request_template.md
|
65
70
|
- lib/sharepoint_api.rb
|
66
71
|
- lib/sharepoint_api/file_info.rb
|
67
72
|
- lib/sharepoint_api/file_system.rb
|
@@ -95,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
100
|
- !ruby/object:Gem::Version
|
96
101
|
version: '0'
|
97
102
|
requirements: []
|
98
|
-
rubygems_version: 3.
|
103
|
+
rubygems_version: 3.2.4
|
99
104
|
signing_key:
|
100
105
|
specification_version: 4
|
101
106
|
summary: SharepointApi allows you to interact with sharepoint in a simpler DSL.
|