Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

allow users to check their org/team access

  • Loading branch information...
commit 18f3cae4e993a6177eb8240613f88f9404d962ec 1 parent 41a2bb1
@atmos atmos authored
View
62 lib/warden-github/user.rb
@@ -21,6 +21,68 @@ def email
def company
attribs['company']
end
+
+ # See if the user is a public member of the named organization
+ #
+ # name - the organization name
+ #
+ # Returns: true if the user is publicized as an org member
+ def publicized_organization_member?(org_name)
+ members = github_request("orgs/#{name}/public_members")
+ members.map { |org| org["login"] }.include?(login)
+ rescue RestClient::Forbidden, RestClient::Unauthorized, RestClient::ResourceNotFound => e
+ false
+ end
+
+ # See if the user is a member of the named organization
+ #
+ # name - the organization name
+ #
+ # Returns: true if the user has access, false otherwise
+ def organization_member?(name)
+ orgs = github_request("orgs/#{name}/members")
+ orgs.map { |org| org["login"] }.include?(github_user.login)
+ rescue RestClient::Forbidden, RestClient::Unauthorized, RestClient::ResourceNotFound => e
+ false
+ end
+
+ # See if the user is a member of the team id
+ #
+ # team_id - the team's id
+ #
+ # Returns: true if the user has access, false otherwise
+ def team_member?(team_id)
+ members = github_request("teams/#{team_id}/members")
+ members.map { |user| user["login"] }.include?(login)
+ rescue RestClient::Forbidden, RestClient::Unauthorized, RestClient::ResourceNotFound => e
+ false
+ end
+
+ # Send a V3 API GET request to path and parse the response body
+ #
+ # path - the path on api.github.com to hit
+ #
+ # Returns a parsed JSON response
+ #
+ # Examples
+ # github_request("/user")
+ # # => { 'login' => 'atmos', ... }
+ def github_request(path)
+ Yajl.load(github_raw_request(path))
+ end
+
+ # Send a V3 API GET request to path
+ #
+ # path - the path on api.github.com to hit
+ #
+ # Returns a rest client response object
+ #
+ # Examples
+ # github_raw_request("/user")
+ # # => RestClient::Response
+ def github_raw_request(path)
+ RestClient.get("#{github_api_uri}/#{path}", :params => { :access_token => token }, :accept => :json)
+ end
end
end
end
View
5 spec/proxy_spec.rb
@@ -5,14 +5,15 @@
sha = Digest::SHA1.hexdigest(Time.now.to_s)
@proxy = Warden::Github::Oauth::Proxy.new(sha[0..19], sha[0..39],
'user,public_repo,repo,gist',
+ 'http://example.org',
'http://example.org/auth/github/callback')
end
it "returns an authorize url" do
uri = Addressable::URI.parse(@proxy.authorize_url)
- uri.scheme.should eql('https')
- uri.host.should eql('github.com')
+ uri.scheme.should eql('http')
+ uri.host.should eql('example.org')
params = uri.query_values
params['response_type'].should eql('code')
View
2  spec/spec_helper.rb
@@ -4,7 +4,7 @@
require File.join(File.dirname(__FILE__), 'app')
require 'rack/test'
require 'webrat'
-
+require 'addressable/uri'
require 'pp'
Webrat.configure do |config|
Please sign in to comment.
Something went wrong with that request. Please try again.