sinatra_auth_github 0.0.15 → 0.0.16

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.
@@ -35,23 +35,34 @@ module Sinatra
35
35
  warden.user
36
36
  end
37
37
 
38
+ # API Requests
38
39
  def github_request(path)
39
40
  response = RestClient.get "https://github.com/api/v2/json/#{path}", :params => { :access_token => github_user.token }, :accept => :json
40
41
  JSON.parse(response.body)
41
42
  end
42
43
 
44
+ # Access Inquiries
45
+ def github_organization_access?(name)
46
+ orgs = github_request("user/show/#{github_user.login}/organizations")["organizations"]
47
+ orgs.map { |org| org["login"] }.include?(name)
48
+ end
49
+
50
+ def github_organization_team_access?(name, team)
51
+ members = github_request("teams/#{team}/members")["users"]
52
+ members.map { |user| user["login"] }.include?(github_user.login)
53
+ rescue RestClient::Unauthorized => e
54
+ false
55
+ end
56
+
57
+ # Auth only certain individuals
43
58
  def github_organization_authenticate!(name)
44
59
  authenticate!
45
- orgs = github_request("user/show/#{github_user.login}/organizations")["organizations"]
46
- halt([401, "Unauthorized User"]) unless orgs.map { |org| org["login"] }.include?(name)
60
+ halt([401, "Unauthorized User"]) unless github_organization_access?(name)
47
61
  end
48
62
 
49
63
  def github_organization_team_authenticate!(name, team)
50
64
  authenticate!
51
- members = github_request("teams/#{team}/members")["users"]
52
- halt([401, "Unauthorized User"]) unless members.map { |user| user["login"] }.include?(github_user.login)
53
- rescue RestClient::Unauthorized => e
54
- halt([401, "Unauthorized User"])
65
+ halt([401, "Unauthorized User"]) unless github_organization_team_access?(name, team)
55
66
  end
56
67
 
57
68
  def _relative_url_for(path)
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "sinatra_auth_github"
6
- s.version = "0.0.15"
6
+ s.version = "0.0.16"
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["Corey Donohoe"]
9
9
  s.email = ["atmos@atmos.org"]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra_auth_github
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 63
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 15
10
- version: 0.0.15
9
+ - 16
10
+ version: 0.0.16
11
11
  platform: ruby
12
12
  authors:
13
13
  - Corey Donohoe