add-to-org 2.2.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.bowerrc +3 -0
  3. data/.gitignore +7 -0
  4. data/.ruby-version +1 -1
  5. data/README.md +68 -25
  6. data/bower.json +15 -0
  7. data/lib/add-to-org/helpers.rb +13 -11
  8. data/lib/add-to-org/public/vendor/bootstrap/.bower.json +45 -0
  9. data/lib/add-to-org/public/vendor/bootstrap/LICENSE +21 -0
  10. data/lib/add-to-org/public/vendor/bootstrap/bower.json +34 -0
  11. data/lib/add-to-org/public/vendor/bootstrap/dist/css/bootstrap-theme.css +587 -0
  12. data/lib/add-to-org/public/vendor/bootstrap/dist/css/bootstrap-theme.css.map +1 -0
  13. data/lib/add-to-org/public/vendor/bootstrap/dist/css/bootstrap-theme.min.css +6 -0
  14. data/lib/add-to-org/public/vendor/bootstrap/dist/css/bootstrap-theme.min.css.map +1 -0
  15. data/lib/add-to-org/public/vendor/bootstrap/dist/css/bootstrap.css +6760 -0
  16. data/lib/add-to-org/public/vendor/bootstrap/dist/css/bootstrap.css.map +1 -0
  17. data/lib/add-to-org/public/vendor/bootstrap/dist/css/bootstrap.min.css +6 -0
  18. data/lib/add-to-org/public/vendor/bootstrap/dist/css/bootstrap.min.css.map +1 -0
  19. data/lib/add-to-org/public/vendor/bootstrap/dist/fonts/glyphicons-halflings-regular.eot +0 -0
  20. data/lib/add-to-org/public/vendor/bootstrap/dist/fonts/glyphicons-halflings-regular.svg +288 -0
  21. data/lib/add-to-org/public/vendor/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf +0 -0
  22. data/lib/add-to-org/public/vendor/bootstrap/dist/fonts/glyphicons-halflings-regular.woff +0 -0
  23. data/lib/add-to-org/public/vendor/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2 +0 -0
  24. data/lib/add-to-org/public/vendor/bootstrap/dist/js/bootstrap.js +2363 -0
  25. data/lib/add-to-org/public/vendor/bootstrap/dist/js/bootstrap.min.js +7 -0
  26. data/lib/add-to-org/public/vendor/bootstrap/dist/js/npm.js +13 -0
  27. data/lib/add-to-org/public/vendor/bootstrap/fonts/glyphicons-halflings-regular.eot +0 -0
  28. data/lib/add-to-org/public/vendor/bootstrap/fonts/glyphicons-halflings-regular.svg +288 -0
  29. data/lib/add-to-org/public/vendor/bootstrap/fonts/glyphicons-halflings-regular.ttf +0 -0
  30. data/lib/add-to-org/public/vendor/bootstrap/fonts/glyphicons-halflings-regular.woff +0 -0
  31. data/lib/add-to-org/public/vendor/bootstrap/fonts/glyphicons-halflings-regular.woff2 +0 -0
  32. data/lib/add-to-org/public/vendor/bootstrap/package.json +87 -0
  33. data/lib/add-to-org/version.rb +1 -1
  34. data/lib/add-to-org/views/error.erb +5 -12
  35. data/lib/add-to-org/views/forbidden.erb +5 -12
  36. data/lib/add-to-org/views/layout.erb +24 -0
  37. data/lib/add-to-org/views/success.erb +5 -12
  38. data/lib/add-to-org.rb +38 -3
  39. data/spec/add-to-org-helpers_spec.rb +15 -10
  40. data/spec/add-to-org_spec.rb +74 -47
  41. data/spec/spec_helper.rb +1 -1
  42. metadata +31 -3
@@ -1,12 +1,5 @@
1
- <html>
2
- <head>
3
- <style>
4
- body { padding: 20px; }
5
- </style>
6
- </head>
7
- <body>
8
- <h1>Sorry Charlie</h1>
9
- <p>We're unable to verify your eligibility at this time.</p>
10
- <p>Please contact <a href="mailto:<%= ENV['CONTACT_EMAIL'] %>"><%= ENV['CONTACT_EMAIL'] %></a> if you believe this is in error.</p>
11
- </body>
12
- </html>
1
+ <h1>Sorry Charlie</h1>
2
+
3
+ <p>We're unable to verify your eligibility at this time.</p>
4
+
5
+ <p>Please contact <a href="mailto:<%= ENV['CONTACT_EMAIL'] %>"><%= ENV['CONTACT_EMAIL'] %></a> if you believe this is in error.</p>
@@ -0,0 +1,24 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1">
7
+ <title>Join <%= ENV['GITHUB_ORG_ID'] %></title>
8
+
9
+ <link rel="stylesheet" href="/vendor/bootstrap/dist/css/bootstrap.min.css">
10
+ <link rel="stylesheet" href="/vendor/bootstrap/dist/css/bootstrap-theme.min.css">
11
+
12
+ <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
13
+ <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
14
+ <!--[if lt IE 9]>
15
+ <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
16
+ <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
17
+ <![endif]-->
18
+ </head>
19
+ <body>
20
+ <div class="container">
21
+ <%= yield %>
22
+ </div>
23
+ </body>
24
+ </html>
@@ -1,12 +1,5 @@
1
- <html>
2
- <head>
3
- <style>
4
- body { padding: 20px; }
5
- </style>
6
- </head>
7
- <body>
8
- <h1>You're all set</h1>
9
- <p class="lead">You simply need to <a href="https://github.com/orgs/<%= org_id %>/invitation?return_to=<%= ERB::Util.html_escape(redirect) %>">confirm your invitation to join the organization</a> on GitHub.</p>
10
- <p>Once confirmed, you will have access to <a href="<%= ERB::Util.html_escape(redirect) %>"><%= ERB::Util.html_escape(redirect) %></a>, the requested URL.</h1>
11
- </body>
12
- </html>
1
+ <h1>You're all set</h1>
2
+
3
+ <p class="lead">You simply need to <a href="https://github.com/orgs/<%= org_id %>/invitation?return_to=<%= ERB::Util.html_escape(redirect) %>">confirm your invitation to join the organization</a> on GitHub.</p>
4
+
5
+ <p>Once confirmed, you will have access to <a href="<%= ERB::Util.html_escape(redirect) %>"><%= ERB::Util.html_escape(redirect) %></a>, the requested URL.</h1>
data/lib/add-to-org.rb CHANGED
@@ -3,9 +3,40 @@ require 'sinatra_auth_github'
3
3
  require 'dotenv'
4
4
  require_relative 'add-to-org/helpers'
5
5
 
6
- Dotenv.load
7
-
8
6
  module AddToOrg
7
+
8
+ def self.root
9
+ File.expand_path "./add-to-org", File.dirname(__FILE__)
10
+ end
11
+
12
+ def self.views_dir
13
+ @views_dir ||= File.expand_path "views", AddToOrg.root
14
+ end
15
+
16
+ def self.views_dir=(dir)
17
+ @views_dir = dir
18
+ end
19
+
20
+ def self.public_dir
21
+ @public_dir ||= File.expand_path "public", AddToOrg.root
22
+ end
23
+
24
+ def self.public_dir=(dir)
25
+ @public_dir = dir
26
+ end
27
+
28
+ def self.validator=(validator)
29
+ @validator = validator
30
+ end
31
+
32
+ def self.set_validator(&block)
33
+ @validator = block
34
+ end
35
+
36
+ def self.validator
37
+ @validator ||= Proc.new { raise "You must define a custom validator to determine eligibility" }
38
+ end
39
+
9
40
  class App < Sinatra::Base
10
41
 
11
42
  include AddToOrg::Helpers
@@ -22,7 +53,9 @@ module AddToOrg
22
53
  ENV['WARDEN_GITHUB_VERIFIER_SECRET'] ||= SecureRandom.hex
23
54
  register Sinatra::Auth::Github
24
55
 
25
- set :views, File.expand_path("add-to-org/views", File.dirname(__FILE__))
56
+ set :views, Proc.new { AddToOrg.views_dir }
57
+ set :root, Proc.new { AddToOrg.root }
58
+ set :public_folder, Proc.new { AddToOrg.public_dir }
26
59
 
27
60
  # require ssl
28
61
  configure :production do
@@ -65,3 +98,5 @@ module AddToOrg
65
98
  end
66
99
  end
67
100
  end
101
+
102
+ Dotenv.load unless AddToOrg::App.production?
@@ -23,14 +23,14 @@ describe "AddToOrgHelpers" do
23
23
  end
24
24
 
25
25
  it "initializes the client" do
26
- expect(@helper.client.class).to eql(Octokit::Client)
27
- expect(@helper.client.instance_variable_get("@access_token")).to eql("asdf1234")
26
+ expect(@helper.send(:client).class).to eql(Octokit::Client)
27
+ expect(@helper.send(:client).instance_variable_get("@access_token")).to eql("asdf1234")
28
28
  end
29
29
 
30
30
  it "initializes the sudo client" do
31
31
  with_env "GITHUB_TOKEN", "SUDO_TOKEN" do
32
- expect(@helper.sudo_client.class).to eql(Octokit::Client)
33
- expect(@helper.sudo_client.instance_variable_get("@access_token")).to eql("SUDO_TOKEN")
32
+ expect(@helper.send(:sudo_client).class).to eql(Octokit::Client)
33
+ expect(@helper.send(:sudo_client).instance_variable_get("@access_token")).to eql("SUDO_TOKEN")
34
34
  end
35
35
  end
36
36
 
@@ -43,13 +43,13 @@ describe "AddToOrgHelpers" do
43
43
 
44
44
  it "retrieves the org id" do
45
45
  with_env "GITHUB_ORG_ID", "some_org" do
46
- expect(@helper.org_id).to eql("some_org")
46
+ expect(@helper.send(:org_id)).to eql("some_org")
47
47
  end
48
48
  end
49
49
 
50
50
  it "retrieves the team id" do
51
51
  with_env "GITHUB_TEAM_ID", "1234" do
52
- expect(@helper.team_id).to eql("1234")
52
+ expect(@helper.send(:team_id)).to eql("1234")
53
53
  end
54
54
  end
55
55
 
@@ -57,11 +57,11 @@ describe "AddToOrgHelpers" do
57
57
  with_env "GITHUB_ORG_ID", "some_org" do
58
58
  stub_request(:get, "https://api.github.com/orgs/some_org/members/benbaltertest").
59
59
  to_return(:status => 204)
60
- expect(@helper.member?).to eql(true)
60
+ expect(@helper.send(:member?)).to eql(true)
61
61
 
62
62
  stub_request(:get, "https://api.github.com/orgs/some_org/members/benbaltertest").
63
63
  to_return(:status => 404)
64
- expect(@helper.member?).to eql(false)
64
+ expect(@helper.send(:member?)).to eql(false)
65
65
  end
66
66
  end
67
67
 
@@ -69,12 +69,17 @@ describe "AddToOrgHelpers" do
69
69
  with_env "GITHUB_ORG_ID", "some_org" do
70
70
  stub = stub_request(:put, "https://api.github.com/teams/memberships/benbaltertest").
71
71
  to_return(:status => 204)
72
- @helper.add
72
+ @helper.send(:add)
73
73
  expect(stub).to have_been_requested
74
74
  end
75
75
  end
76
76
 
77
77
  it "throws an error if valid? is not defined" do
78
- expect { @helper.valid? }.to raise_error("You must define a custom valid? method to determine eligibility")
78
+ stub_request(:get, "https://api.github.com/user/emails").
79
+ to_return(:status => 200, :body => fixture("emails.json"), :headers => { 'Content-Type'=>'application/json' })
80
+
81
+ AddToOrg.validator = nil
82
+ error = "You must define a custom validator to determine eligibility"
83
+ expect { @helper.valid? }.to raise_error(error)
79
84
  end
80
85
  end
@@ -1,5 +1,19 @@
1
1
  require "spec_helper"
2
2
 
3
+ describe "config" do
4
+ [:views_dir, :public_dir, :validator].each do |var|
5
+ after do
6
+ AddToOrg.send("#{var}=", nil)
7
+ end
8
+
9
+ it "accepts #{var}" do
10
+ expected = SecureRandom.hex
11
+ AddToOrg.send("#{var}=", expected)
12
+ expect(AddToOrg.send(var)).to eql(expected)
13
+ end
14
+ end
15
+ end
16
+
3
17
  describe "logged out user" do
4
18
 
5
19
  include Rack::Test::Methods
@@ -19,14 +33,6 @@ describe "logged in user" do
19
33
 
20
34
  include Rack::Test::Methods
21
35
 
22
- module AddToOrg
23
- class App < Sinatra::Base
24
- def valid?
25
- verified_emails.any? { |email| email[:email] =~ /@github\.com$/}
26
- end
27
- end
28
- end
29
-
30
36
  def app
31
37
  AddToOrg::App
32
38
  end
@@ -54,55 +60,76 @@ describe "logged in user" do
54
60
  end
55
61
  end
56
62
 
57
- it "denies acccess to invalid users" do
58
- with_env "GITHUB_ORG_ID", "some_org" do
59
- stub_request(:get, "https://api.github.com/orgs/some_org/members/benbaltertest").
60
- to_return(:status => 404)
63
+ [:proc, :block, :lambda].each do |method|
64
+ describe "with validator passed as a #{method}" do
65
+
66
+ before(:each) do
67
+ if method == :block
68
+ AddToOrg.set_validator do |github_user, verified_emails, client|
69
+ verified_emails.any? { |email| email[:email] =~ /@github\.com$/ }
70
+ end
71
+ elsif method == :proc
72
+ AddToOrg.validator = proc { |github_user, verified_emails, client|
73
+ verified_emails.any? { |email| email[:email] =~ /@github\.com$/ }
74
+ }
75
+ elsif method == :lambda
76
+ AddToOrg.validator = lambda { |github_user, verified_emails, client|
77
+ verified_emails.any? { |email| email[:email] =~ /@github\.com$/ }
78
+ }
79
+ end
80
+ end
61
81
 
62
- stub_request(:get, "https://api.github.com/user/emails").
63
- to_return(:status => 200, :body => fixture("invalid_emails.json"), :headers => { 'Content-Type'=>'application/json' })
82
+ it "denies acccess to invalid users" do
83
+ with_env "GITHUB_ORG_ID", "some_org" do
84
+ stub_request(:get, "https://api.github.com/orgs/some_org/members/benbaltertest").
85
+ to_return(:status => 404)
64
86
 
65
- get "/"
66
- expect(last_response.status).to eql(403)
67
- expect(last_response.body).to match(/We're unable to verify your eligibility at this time/)
68
- end
69
- end
87
+ stub_request(:get, "https://api.github.com/user/emails").
88
+ to_return(:status => 200, :body => fixture("invalid_emails.json"), :headers => { 'Content-Type'=>'application/json' })
70
89
 
71
- it "tries to add valid users" do
72
- with_env "GITHUB_ORG_ID", "some_org" do
73
- stub_request(:get, "https://api.github.com/orgs/some_org/members/benbaltertest").
74
- to_return(:status => 404)
90
+ get "/"
91
+ expect(last_response.status).to eql(403)
92
+ expect(last_response.body).to match(/We're unable to verify your eligibility at this time/)
93
+ end
94
+ end
75
95
 
76
- stub_request(:get, "https://api.github.com/user/emails").
77
- to_return(:status => 200, :body => fixture("emails.json"), :headers => { 'Content-Type'=>'application/json' })
96
+ it "tries to add valid users" do
97
+ with_env "GITHUB_ORG_ID", "some_org" do
98
+ stub_request(:get, "https://api.github.com/orgs/some_org/members/benbaltertest").
99
+ to_return(:status => 404)
78
100
 
79
- stub = stub_request(:put, "https://api.github.com/teams/memberships/benbaltertest").
80
- to_return(:status => 204)
101
+ stub_request(:get, "https://api.github.com/user/emails").
102
+ to_return(:status => 200, :body => fixture("emails.json"), :headers => { 'Content-Type'=>'application/json' })
81
103
 
82
- get "/foo"
83
- expect(stub).to have_been_requested
84
- expect(last_response.status).to eql(200)
85
- expect(last_response.body).to match(/confirm your invitation to join the organization/)
86
- expect(last_response.body).to match(/https:\/\/github.com\/orgs\/some_org\/invitation/)
87
- expect(last_response.body).to match(/\?return_to=https:\/\/github.com\/foo/)
88
- end
89
- end
104
+ stub = stub_request(:put, "https://api.github.com/teams/memberships/benbaltertest").
105
+ to_return(:status => 204)
90
106
 
91
- it "includes the requested URL" do
92
- with_env "GITHUB_ORG_ID", "some_org" do
93
- stub_request(:get, "https://api.github.com/orgs/some_org/members/benbaltertest").
94
- to_return(:status => 404)
107
+ get "/foo"
108
+ expect(stub).to have_been_requested
109
+ expect(last_response.status).to eql(200)
110
+ expect(last_response.body).to match(/confirm your invitation to join the organization/)
111
+ expect(last_response.body).to match(/https:\/\/github.com\/orgs\/some_org\/invitation/)
112
+ expect(last_response.body).to match(/\?return_to=https:\/\/github.com\/foo/)
113
+ end
114
+ end
95
115
 
96
- stub_request(:get, "https://api.github.com/user/emails").
97
- to_return(:status => 200, :body => fixture("emails.json"), :headers => { 'Content-Type'=>'application/json' })
116
+ it "includes the requested URL" do
117
+ with_env "GITHUB_ORG_ID", "some_org" do
118
+ stub_request(:get, "https://api.github.com/orgs/some_org/members/benbaltertest").
119
+ to_return(:status => 404)
98
120
 
99
- stub = stub_request(:put, "https://api.github.com/teams/memberships/benbaltertest").
100
- to_return(:status => 204)
121
+ stub_request(:get, "https://api.github.com/user/emails").
122
+ to_return(:status => 200, :body => fixture("emails.json"), :headers => { 'Content-Type'=>'application/json' })
101
123
 
102
- get "/foo/bar"
103
- expect(stub).to have_been_requested
104
- expect(last_response.status).to eql(200)
105
- expect(last_response.body).to match(Regexp.new('<a href="https://github.com/foo/bar">https://github.com/foo/bar</a>'))
124
+ stub = stub_request(:put, "https://api.github.com/teams/memberships/benbaltertest").
125
+ to_return(:status => 204)
126
+
127
+ get "/foo/bar"
128
+ expect(stub).to have_been_requested
129
+ expect(last_response.status).to eql(200)
130
+ expect(last_response.body).to match(Regexp.new('<a href="https://github.com/foo/bar">https://github.com/foo/bar</a>'))
131
+ end
132
+ end
106
133
  end
107
134
  end
108
135
  end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "bundler/setup"
2
2
  require 'fileutils'
3
+ require 'securerandom'
3
4
 
4
5
  ENV['RACK_ENV'] = 'test'
5
6
  ENV['GITHUB_CLIENT_ID'] = "CLIENT_ID"
@@ -26,7 +27,6 @@ def fixture(fixture)
26
27
  File.open(fixture_path(fixture)).read
27
28
  end
28
29
 
29
-
30
30
  def with_env(key, value)
31
31
  old_env = ENV[key]
32
32
  ENV[key] = value
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: add-to-org
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Balter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-16 00:00:00.000000000 Z
11
+ date: 2015-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: warden-github
@@ -156,6 +156,7 @@ executables: []
156
156
  extensions: []
157
157
  extra_rdoc_files: []
158
158
  files:
159
+ - ".bowerrc"
159
160
  - ".gitignore"
160
161
  - ".ruby-version"
161
162
  - ".travis.yml"
@@ -164,11 +165,38 @@ files:
164
165
  - README.md
165
166
  - Rakefile
166
167
  - add-to-org.gemspec
168
+ - bower.json
167
169
  - lib/add-to-org.rb
168
170
  - lib/add-to-org/helpers.rb
171
+ - lib/add-to-org/public/vendor/bootstrap/.bower.json
172
+ - lib/add-to-org/public/vendor/bootstrap/LICENSE
173
+ - lib/add-to-org/public/vendor/bootstrap/bower.json
174
+ - lib/add-to-org/public/vendor/bootstrap/dist/css/bootstrap-theme.css
175
+ - lib/add-to-org/public/vendor/bootstrap/dist/css/bootstrap-theme.css.map
176
+ - lib/add-to-org/public/vendor/bootstrap/dist/css/bootstrap-theme.min.css
177
+ - lib/add-to-org/public/vendor/bootstrap/dist/css/bootstrap-theme.min.css.map
178
+ - lib/add-to-org/public/vendor/bootstrap/dist/css/bootstrap.css
179
+ - lib/add-to-org/public/vendor/bootstrap/dist/css/bootstrap.css.map
180
+ - lib/add-to-org/public/vendor/bootstrap/dist/css/bootstrap.min.css
181
+ - lib/add-to-org/public/vendor/bootstrap/dist/css/bootstrap.min.css.map
182
+ - lib/add-to-org/public/vendor/bootstrap/dist/fonts/glyphicons-halflings-regular.eot
183
+ - lib/add-to-org/public/vendor/bootstrap/dist/fonts/glyphicons-halflings-regular.svg
184
+ - lib/add-to-org/public/vendor/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf
185
+ - lib/add-to-org/public/vendor/bootstrap/dist/fonts/glyphicons-halflings-regular.woff
186
+ - lib/add-to-org/public/vendor/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2
187
+ - lib/add-to-org/public/vendor/bootstrap/dist/js/bootstrap.js
188
+ - lib/add-to-org/public/vendor/bootstrap/dist/js/bootstrap.min.js
189
+ - lib/add-to-org/public/vendor/bootstrap/dist/js/npm.js
190
+ - lib/add-to-org/public/vendor/bootstrap/fonts/glyphicons-halflings-regular.eot
191
+ - lib/add-to-org/public/vendor/bootstrap/fonts/glyphicons-halflings-regular.svg
192
+ - lib/add-to-org/public/vendor/bootstrap/fonts/glyphicons-halflings-regular.ttf
193
+ - lib/add-to-org/public/vendor/bootstrap/fonts/glyphicons-halflings-regular.woff
194
+ - lib/add-to-org/public/vendor/bootstrap/fonts/glyphicons-halflings-regular.woff2
195
+ - lib/add-to-org/public/vendor/bootstrap/package.json
169
196
  - lib/add-to-org/version.rb
170
197
  - lib/add-to-org/views/error.erb
171
198
  - lib/add-to-org/views/forbidden.erb
199
+ - lib/add-to-org/views/layout.erb
172
200
  - lib/add-to-org/views/success.erb
173
201
  - script/bootstrap
174
202
  - script/cibuild
@@ -199,7 +227,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
199
227
  version: '0'
200
228
  requirements: []
201
229
  rubyforge_project:
202
- rubygems_version: 2.4.8
230
+ rubygems_version: 2.5.1
203
231
  signing_key:
204
232
  specification_version: 4
205
233
  summary: A simple Oauth App to automatically add users to an organization