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.
- checksums.yaml +4 -4
- data/.bowerrc +3 -0
- data/.gitignore +7 -0
- data/.ruby-version +1 -1
- data/README.md +68 -25
- data/bower.json +15 -0
- data/lib/add-to-org/helpers.rb +13 -11
- data/lib/add-to-org/public/vendor/bootstrap/.bower.json +45 -0
- data/lib/add-to-org/public/vendor/bootstrap/LICENSE +21 -0
- data/lib/add-to-org/public/vendor/bootstrap/bower.json +34 -0
- data/lib/add-to-org/public/vendor/bootstrap/dist/css/bootstrap-theme.css +587 -0
- data/lib/add-to-org/public/vendor/bootstrap/dist/css/bootstrap-theme.css.map +1 -0
- data/lib/add-to-org/public/vendor/bootstrap/dist/css/bootstrap-theme.min.css +6 -0
- data/lib/add-to-org/public/vendor/bootstrap/dist/css/bootstrap-theme.min.css.map +1 -0
- data/lib/add-to-org/public/vendor/bootstrap/dist/css/bootstrap.css +6760 -0
- data/lib/add-to-org/public/vendor/bootstrap/dist/css/bootstrap.css.map +1 -0
- data/lib/add-to-org/public/vendor/bootstrap/dist/css/bootstrap.min.css +6 -0
- data/lib/add-to-org/public/vendor/bootstrap/dist/css/bootstrap.min.css.map +1 -0
- data/lib/add-to-org/public/vendor/bootstrap/dist/fonts/glyphicons-halflings-regular.eot +0 -0
- data/lib/add-to-org/public/vendor/bootstrap/dist/fonts/glyphicons-halflings-regular.svg +288 -0
- data/lib/add-to-org/public/vendor/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf +0 -0
- data/lib/add-to-org/public/vendor/bootstrap/dist/fonts/glyphicons-halflings-regular.woff +0 -0
- data/lib/add-to-org/public/vendor/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2 +0 -0
- data/lib/add-to-org/public/vendor/bootstrap/dist/js/bootstrap.js +2363 -0
- data/lib/add-to-org/public/vendor/bootstrap/dist/js/bootstrap.min.js +7 -0
- data/lib/add-to-org/public/vendor/bootstrap/dist/js/npm.js +13 -0
- data/lib/add-to-org/public/vendor/bootstrap/fonts/glyphicons-halflings-regular.eot +0 -0
- data/lib/add-to-org/public/vendor/bootstrap/fonts/glyphicons-halflings-regular.svg +288 -0
- data/lib/add-to-org/public/vendor/bootstrap/fonts/glyphicons-halflings-regular.ttf +0 -0
- data/lib/add-to-org/public/vendor/bootstrap/fonts/glyphicons-halflings-regular.woff +0 -0
- data/lib/add-to-org/public/vendor/bootstrap/fonts/glyphicons-halflings-regular.woff2 +0 -0
- data/lib/add-to-org/public/vendor/bootstrap/package.json +87 -0
- data/lib/add-to-org/version.rb +1 -1
- data/lib/add-to-org/views/error.erb +5 -12
- data/lib/add-to-org/views/forbidden.erb +5 -12
- data/lib/add-to-org/views/layout.erb +24 -0
- data/lib/add-to-org/views/success.erb +5 -12
- data/lib/add-to-org.rb +38 -3
- data/spec/add-to-org-helpers_spec.rb +15 -10
- data/spec/add-to-org_spec.rb +74 -47
- data/spec/spec_helper.rb +1 -1
- metadata +31 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a99e18aeff2a09664bc9027c2a846413627aa65
|
4
|
+
data.tar.gz: 9114cbaa5a4dc8505d148460ad5bcf24585bac2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a00ca8dd28bf2f8b0fc6e68dbfc56076c5355af8aff911aedbd7526d38b0248f1968dc51a0930eefa3e5c93eae5227137762a443f30b7f6329e969eff86541c5
|
7
|
+
data.tar.gz: 90005db4a120915bbec411040cf82bdf8c6c514a3a6e00f87ad437f4dda801844a4c8ad2f56d13eb37658b5911ade07589dab211f4ff058a5b556c5dc1afa062
|
data/.bowerrc
ADDED
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.
|
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
|
-
|
14
|
-
|
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
|
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
|
-
|
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
|
-
|
40
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
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
|
-
|
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
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
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
|
+
}
|
data/lib/add-to-org/helpers.rb
CHANGED
@@ -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
|
-
#
|
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
|
+
}
|