add-to-org 2.2.1 → 3.0.0

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.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 82b5c39679b1c2a027a7e88d6e89ac6f2bb51943
4
- data.tar.gz: dfed027da8d511c120088cfaf1499f57d7e8323b
3
+ metadata.gz: 1a99e18aeff2a09664bc9027c2a846413627aa65
4
+ data.tar.gz: 9114cbaa5a4dc8505d148460ad5bcf24585bac2d
5
5
  SHA512:
6
- metadata.gz: da885134a8f2dae8e38fdeda232e35ddc30476a5664770b5e894a7c32ce385e98e1cb3d29da71ce7627fb0180a419fc53249233ea9846879adfcb5d7695c0b89
7
- data.tar.gz: 9c6b02fce59bdcc578a83804b72880d70ea2d6f58088abe7acccafd8cd24781766601ac3a48cff5a795d78b1199cef81c64af8145bd940270bc65542f3552884
6
+ metadata.gz: a00ca8dd28bf2f8b0fc6e68dbfc56076c5355af8aff911aedbd7526d38b0248f1968dc51a0930eefa3e5c93eae5227137762a443f30b7f6329e969eff86541c5
7
+ data.tar.gz: 90005db4a120915bbec411040cf82bdf8c6c514a3a6e00f87ad437f4dda801844a4c8ad2f56d13eb37658b5911ade07589dab211f4ff058a5b556c5dc1afa062
data/.bowerrc ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "directory": "lib/add-to-org/public/vendor"
3
+ }
data/.gitignore CHANGED
@@ -2,3 +2,10 @@
2
2
  .bundle
3
3
  *.gem
4
4
  Gemfile.lock
5
+ /lib/add-to-org/public/vendor/jquery
6
+ /lib/add-to-org/public/vendor/bootstrap/grunt
7
+ /lib/add-to-org/public/vendor/bootstrap/js
8
+ /lib/add-to-org/public/vendor/bootstrap/less
9
+ /lib/add-to-org/public/vendor/bootstrap/nuget
10
+ /lib/add-to-org/public/vendor/bootstrap/*.md
11
+ /lib/add-to-org/public/vendor/bootstrap/*.js
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.2.3
1
+ 2.3.0
data/README.md CHANGED
@@ -10,10 +10,35 @@ Once set up, simply swap out your app's domain for any GitHub URL. E.g., `github
10
10
 
11
11
  ## Setup
12
12
 
13
- 1. Create [an oauth app](github.com/settings/applications/new)
14
- 2. Create a personal access token for a user with admin rights to the organization
13
+ *Pro-tip: for a quickstart on how to set up the app, see the [add-to-org demo app](https://github.com/benbalter/add-to-org-demo).*
14
+
15
+ ### Credentials
16
+
17
+ You'll need a few different credentials for things to work:
18
+
19
+ #### A bot account
20
+
21
+ You'll need a dedicated "bot" account to add users to the organization:
22
+
23
+ 1. [Create a bot account](https://github.com/signup) (a standard GitHub account not used by a human) that has *admin* rights to your organization.
24
+ 2. [Create a personal access token](https://github.com/settings/tokens/new) for that user, with `admin:org` scope.
25
+
26
+ #### An OAuth application
27
+
28
+ You'll also need to create an OAUth application to validate users:
29
+
30
+ 1. Create an OAauth application *within your organization* via `https://github.com/organizations/[YOUR-ORGANIZATION-NAME]/settings/applications/new`
31
+ 2. The homepage URL should be the URL to your production instance.
32
+ 3. You can leave the callback URL blank. The default is fine.
33
+
34
+ ## Developing locally and deploying
35
+
36
+ *Pro-tip: for a quickstart on how to set up the app, see the [add-to-org demo app](https://github.com/benbalter/add-to-org-demo)*
37
+
38
+ 1. Create [an oauth app](github.com/settings/applications/new) (see above)
39
+ 2. Create a personal access token for a user with admin rights to the organization (see above)
15
40
  3. Add `gem 'add-to-org' to your project's Gemfile
16
- 4. Add the following to a `config.ru` file:
41
+ 4. Add the following to your project's `config.ru` file:
17
42
 
18
43
  ```ruby
19
44
  require 'add-to-org'
@@ -31,40 +56,58 @@ The following environmental values should be set:
31
56
  * `GITHUB_TOKEN` - A personal access token for a user with admin rights to the organization
32
57
  * `CONTACT_EMAIL` - Point of contact to point users to if something goes wrong
33
58
 
34
- You'll also need to monkey patch a validation method to determine if a user should be added, e.g.:
59
+ ### Customizing the validator
60
+
61
+ For Add to Org to work, you'll also need to define a custom validator. You can do this in your `configu.ru`, or in a separate file included into `config.ru`. Here's an example of a validator that confirms the user has a verified `@github.com` email address:
35
62
 
36
63
  ```ruby
37
64
  require 'add-to-org'
38
65
 
39
- module AddToOrg
40
- class App < Sinatra::Base
41
- def valid?
42
- verified_emails.any? { |email| email[:email] =~ /@github\.com$/}
43
- end
44
- end
66
+ AddToOrg.set_validator do |github_user, verified_emails, client|
67
+ verified_emails.any? { |email| email[:email] =~ /@github\.com\z/ }
45
68
  end
69
+
70
+ run AddToOrg::App
46
71
  ```
47
72
 
48
- ## Customizing Views
73
+ If you prefer, you can also pass the validator as a proc (or lambda):
74
+
75
+ ```ruby
76
+ AddToOrg.validator = proc { |github_user, verified_emails, client|
77
+ verified_emails.any? { |email| email[:email] =~ /@github\.com\z/ }
78
+ }
79
+ ```
49
80
 
50
- There are three views, `success`, `forbidden`, and `error`. They're pretty boring by default, so you may want to swap them out for something a bit my snazzy. There are two ways to do that:
81
+ The validator will receive three arguments to help you validate the user meets your criteria:
82
+
83
+ * `github_user` - the Warden user, which will contain information like username, company, and human-readable name
84
+ * `verified_emails` - an array of the user's verified emails
85
+ * `client` - An [Octokit.rb](https://github.com/octokit/octokit.rb) client, preset with the user's OAuth token.
86
+
87
+ The validator should return `true` if you'd like the current user added to the organization, or `false` if you'd like the user's request to be denied.
88
+
89
+ ### Customizing Views
90
+
91
+ There are three views, `success`, `forbidden`, and `error`. They're pretty boring by default, so you may want to swap them out for something a bit my snazzy. If you had a views directory along side your `config.ru`, you can do so like this in your `config.ru` file:
51
92
 
52
93
  ```ruby
53
- module AddToOrg
54
- class App < Sinatra::Base
55
- set :views, "path/to/your/views"
56
- end
57
- end
94
+ require 'add-to-org'
95
+
96
+ AddToOrgs.views_dir = File.expand_path("./views", File.dirname(__FILE__))
97
+
98
+ run AddToOrg::App
58
99
  ```
59
100
 
60
- or by overwriting the `success`, `forbidden`, and `error` methods entirely:
101
+ These are just sinatra `.erb` views. Take a look at [the default views](https://github.com/benbalter/add-to-org/tree/master/lib/add-to-org/views) for an example.
102
+
103
+ ### Customizing static assets
104
+
105
+ You can also do the same with `AddToOrg.public_dir` for serving static assets (AddToOrg comes bundled with Bootstrap by default).
61
106
 
62
107
  ```ruby
63
- module AddToOrg
64
- class App < Sinatra::Base
65
- def success(locals={})
66
- halt erb :some_template, :locals => locals
67
- end
68
- end
69
- end
108
+ require 'add-to-org'
109
+
110
+ AddToOrgs.public_dir = File.expand_path("./public", File.dirname(__FILE__))
111
+
112
+ run AddToOrg::App
70
113
  ```
data/bower.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "add-to-org",
3
+ "homepage": "https://github.com/benbalter/add-to-org",
4
+ "authors": [
5
+ "Ben Balter <ben.balter@github.com>"
6
+ ],
7
+ "description": "A simple Oauth App to automatically add users to an organization",
8
+ "main": "script/server",
9
+ "moduleType": [],
10
+ "license": "MIT",
11
+ "private": true,
12
+ "dependencies": {
13
+ "bootstrap": "~3.3.6"
14
+ }
15
+ }
@@ -1,31 +1,33 @@
1
1
  module AddToOrg
2
2
  module Helpers
3
3
 
4
+ # query api for the user's verified emails
5
+ def verified_emails
6
+ emails = client.emails :accept => 'application/vnd.github.v3'
7
+ emails.select { |email| email.verified }
8
+ end
9
+
10
+ def valid?
11
+ AddToOrg.validator.call(github_user, verified_emails, client)
12
+ end
13
+
14
+ private
15
+
4
16
  # user client
5
17
  def client
6
18
  @client ||= Octokit::Client.new :access_token => github_user.token
7
19
  end
8
20
 
9
- # new org admin client
21
+ # org admin client
10
22
  def sudo_client
11
23
  @sudo_client ||= Octokit::Client.new :access_token => ENV['GITHUB_TOKEN']
12
24
  end
13
25
 
14
- # query api for the user's verified emails
15
- def verified_emails
16
- emails = client.emails :accept => 'application/vnd.github.v3'
17
- emails.select { |email| email.verified }
18
- end
19
-
20
26
  # true if user is already a member of the org
21
27
  def member?
22
28
  client.organization_member? org_id, github_user.login
23
29
  end
24
30
 
25
- def valid?
26
- raise "You must define a custom valid? method to determine eligibility"
27
- end
28
-
29
31
  def team_id
30
32
  ENV['GITHUB_TEAM_ID']
31
33
  end
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "bootstrap",
3
+ "description": "The most popular front-end framework for developing responsive, mobile first projects on the web.",
4
+ "keywords": [
5
+ "css",
6
+ "js",
7
+ "less",
8
+ "mobile-first",
9
+ "responsive",
10
+ "front-end",
11
+ "framework",
12
+ "web"
13
+ ],
14
+ "homepage": "http://getbootstrap.com",
15
+ "license": "MIT",
16
+ "moduleType": "globals",
17
+ "main": [
18
+ "less/bootstrap.less",
19
+ "dist/js/bootstrap.js"
20
+ ],
21
+ "ignore": [
22
+ "/.*",
23
+ "_config.yml",
24
+ "CNAME",
25
+ "composer.json",
26
+ "CONTRIBUTING.md",
27
+ "docs",
28
+ "js/tests",
29
+ "test-infra"
30
+ ],
31
+ "dependencies": {
32
+ "jquery": "1.9.1 - 2"
33
+ },
34
+ "version": "3.3.6",
35
+ "_release": "3.3.6",
36
+ "_resolution": {
37
+ "type": "version",
38
+ "tag": "v3.3.6",
39
+ "commit": "81df608a40bf0629a1dc08e584849bb1e43e0b7a"
40
+ },
41
+ "_source": "git://github.com/twbs/bootstrap.git",
42
+ "_target": "~3.3.6",
43
+ "_originalSource": "bootstrap",
44
+ "_direct": true
45
+ }
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2011-2015 Twitter, Inc
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "bootstrap",
3
+ "description": "The most popular front-end framework for developing responsive, mobile first projects on the web.",
4
+ "keywords": [
5
+ "css",
6
+ "js",
7
+ "less",
8
+ "mobile-first",
9
+ "responsive",
10
+ "front-end",
11
+ "framework",
12
+ "web"
13
+ ],
14
+ "homepage": "http://getbootstrap.com",
15
+ "license": "MIT",
16
+ "moduleType": "globals",
17
+ "main": [
18
+ "less/bootstrap.less",
19
+ "dist/js/bootstrap.js"
20
+ ],
21
+ "ignore": [
22
+ "/.*",
23
+ "_config.yml",
24
+ "CNAME",
25
+ "composer.json",
26
+ "CONTRIBUTING.md",
27
+ "docs",
28
+ "js/tests",
29
+ "test-infra"
30
+ ],
31
+ "dependencies": {
32
+ "jquery": "1.9.1 - 2"
33
+ }
34
+ }