sharepoint_api 1.0.0 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f8c46ee759a2cb1b84211e88137406512de21a48a4a759d109097c54273259f
4
- data.tar.gz: 444dbfaee8eff930e0a030ad5cb5450cedc71268eb0ff05ab346af8297c032c9
3
+ metadata.gz: d375981d2a55b77a670835c5c1af3f72226c219c41fdf41ecc0acd97f130a625
4
+ data.tar.gz: fbc8130aed3705b7d69355de908cc97470303d7437233a635fe270c09d8086b1
5
5
  SHA512:
6
- metadata.gz: e1f6ff11efc7b37027928325908e1b05cb5318d1ff4f84fb0a0a10b2253544e54606c7c7043ea1d40257469443412dddebb268629a9cd118331fa4453702b5cb
7
- data.tar.gz: 9f7b3f87f4eaeaf4271a4266ae5f4a054805a5967c471bffde71ca10649e099ce917db9c1aede8e3d8e8dd099ce091f510149ef110a0df3276cf1189bb505b55
6
+ metadata.gz: 45750dcb71e8bcad6bdd11d670df8522205693fe7c08708090782e9ddb5e9c9a6f0d30b152728c9d02951619f47f8a99b296992cc64c6cd1110618c618a86b89
7
+ data.tar.gz: 1d3e0c1da95ecced3228a583552c2900a8f91ff8fb93f46b6363cbfa983fa1fa86ee527f44f14774c1b9db13c314e9b9b0f8ae7901668ed6a78129e89e1d97a9
@@ -1,2 +1,5 @@
1
1
  ## [1.0.0] - 2020-12-07
2
2
  * Initial Release
3
+
4
+ ## [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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- SharepointApi (0.1.0)
4
+ sharepoint_api (1.0.0)
5
5
  addressable (~> 2.7)
6
6
  proof-sharepoint-ruby (~> 1.0)
7
7
 
@@ -64,13 +64,13 @@ PLATFORMS
64
64
  ruby
65
65
 
66
66
  DEPENDENCIES
67
- SharepointApi!
68
67
  faker
69
68
  rake (~> 13.0)
70
69
  rspec (~> 3.6)
71
70
  rspec-collection_matchers
72
71
  rubocop (~> 1.5)
73
72
  rubocop-rspec (~> 2.0)
73
+ sharepoint_api!
74
74
 
75
75
  BUNDLED WITH
76
76
  1.17.2
data/README.md CHANGED
@@ -22,14 +22,37 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ With the appropriate environmental variables set run this in a ruby console.
26
+ Run `bin/console` (after running `bundle install`) to get a pre-loaded ruby console.
26
27
 
28
+ ```ruby
29
+ load 'lib/sharepoint_api.rb'
30
+
31
+ api = SharepointApi.new(
32
+ host: ENV['SHAREPOINT_HOST'],
33
+ site_name: ENV['SHAREPOINT_SITE'],
34
+ library_name: ENV['SHAREPOINT_LIBRARY_NAME'],
35
+ username: ENV['SHAREPOINT_USERNAME'],
36
+ password: ENV['SHAREPOINT_PASSWORD'],
37
+ ntlm: true # for SharePoint 2013, false otherwise
38
+ )
39
+
40
+ api.fetch_content_types # or whatever method you want to test.
41
+ ```
27
42
  ## Development
28
43
 
29
44
  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.
30
45
 
31
46
  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).
32
47
 
48
+ ## Testing
49
+
50
+ Run the test suite:
51
+ `rspec`
52
+
53
+ Run the tests for just one file:
54
+ `rspec spec/sharepoint_api/items_spec.rb`
55
+
33
56
  ## Contributing
34
57
 
35
58
  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).
@@ -65,7 +65,7 @@ class SharepointApi
65
65
  def site_relative_path(path, preview: false)
66
66
  file_path = [
67
67
  library_name, path
68
- ].reject{ |p| p.nil? || p == '' }.join('/')
68
+ ].reject { |p| p.nil? || p == '' }.join('/')
69
69
  encode_path(file_path, preview: preview)
70
70
  end
71
71
 
@@ -29,8 +29,8 @@ class SharepointApi
29
29
  "Lists/GetByTitle('#{encoded_name}')/ContentTypes?" \
30
30
  '$select=Name,StringId'
31
31
  )
32
- response.map { |type| type.data.except('__metadata') }
33
- rescue Sharepoint::SPException => e
32
+ response.map { |content_type| reject_metadata(content_type.data) }
33
+ rescue Sharepoint::SharepointError => e
34
34
  log_as(__method__, e)
35
35
 
36
36
  nil
@@ -67,5 +67,9 @@ class SharepointApi
67
67
  log_as(__method__, error, level: :warn)
68
68
  raise(LockError, error.message)
69
69
  end
70
+
71
+ def reject_metadata(data)
72
+ data.reject { |key| key == '__metadata' }
73
+ end
70
74
  end
71
75
  end
@@ -97,6 +97,29 @@ class SharepointApi
97
97
  false
98
98
  end
99
99
 
100
+ def fetch_role_assignments(path)
101
+ server_path = server_relative_path(path)
102
+ list_item_path = "GetFolderByServerRelativeUrl('#{server_path}')/ListItemAllFields"
103
+ query = '$expand=Member,RoleDefinitionBindings&$select=RoleDefinitionBindings/Name&$select=RoleDefinitionBindings/Id,PrincipalId,Member/LoginName'
104
+
105
+ response = site.query(:get, "#{list_item_path}/RoleAssignments?#{query}")
106
+
107
+ response.map do |assignment|
108
+ data = assignment.data
109
+
110
+ current_roles = data['RoleDefinitionBindings']['results'].map { |rdb| { role_id: rdb['Id'], role_name: rdb['Name'] } }
111
+
112
+ {
113
+ login_name: data['Member']['LoginName'],
114
+ principal_id: data['PrincipalId'],
115
+ roles: current_roles
116
+ }
117
+ end
118
+ rescue Sharepoint::SPException => e
119
+ log_as(__method__, e)
120
+ false
121
+ end
122
+
100
123
  ##
101
124
  # Alternate version would be:
102
125
  # def add_role_assignment(library_guid:, list_item_id:, principal_id:, role_id:)
@@ -1,3 +1,3 @@
1
1
  class SharepointApi
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '1.0.1'.freeze
3
3
  end
@@ -3,8 +3,8 @@ require_relative 'lib/sharepoint_api/version'
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'sharepoint_api'
5
5
  spec.version = SharepointApi::VERSION
6
- spec.authors = ['Andrew Kalek', 'Marlen Brunner']
7
- spec.email = ['akalek@proofgov.com', 'mbrunner@proofgov.com']
6
+ spec.authors = ['Andrew Kalek', 'Marlen Brunner', 'Danella Olsen']
7
+ spec.email = ['akalek@proofgov.com', 'mbrunner@proofgov.com', 'dolsen@proofgov.com']
8
8
 
9
9
  spec.summary = 'SharepointApi allows you to interact with sharepoint in a simpler DSL.'
10
10
  spec.description = 'A tool to make it easier to talk to sharepoint (via the proof-sharepoint-ruby gem)'
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sharepoint_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kalek
8
8
  - Marlen Brunner
9
+ - Danella Olsen
9
10
  autorequire:
10
11
  bindir: exe
11
12
  cert_chain: []
12
- date: 2020-12-07 00:00:00.000000000 Z
13
+ date: 2020-12-14 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: proof-sharepoint-ruby
@@ -44,6 +45,7 @@ description: A tool to make it easier to talk to sharepoint (via the proof-share
44
45
  email:
45
46
  - akalek@proofgov.com
46
47
  - mbrunner@proofgov.com
48
+ - dolsen@proofgov.com
47
49
  executables: []
48
50
  extensions: []
49
51
  extra_rdoc_files: []
@@ -93,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
95
  - !ruby/object:Gem::Version
94
96
  version: '0'
95
97
  requirements: []
96
- rubygems_version: 3.1.4
98
+ rubygems_version: 3.0.3
97
99
  signing_key:
98
100
  specification_version: 4
99
101
  summary: SharepointApi allows you to interact with sharepoint in a simpler DSL.