Skip to content

Commit bbc8e8d

Browse files
committedNov 19, 2015
Code of Conduct support [fixes rauchg#69, thanks @limulus]
1 parent c2430a2 commit bbc8e8d

9 files changed

+93
-6
lines changed
 

‎Procfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
web: bin/slackin --channels "$SLACK_CHANNELS" --port $PORT $SLACK_SUBDOMAIN $SLACK_API_TOKEN
1+
web: bin/slackin --coc "$SLACK_COC" --channels "$SLACK_CHANNELS" --port $PORT $SLACK_SUBDOMAIN $SLACK_API_TOKEN

‎app.json

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
"description": "A Slack API token (find it on https://api.slack.com/web)",
1414
"required": true
1515
},
16+
"SLACK_COC": {
17+
"description": "A URL to a Code of Conduct people must agree on before joining.",
18+
"required": false
19+
},
1620
"SLACK_CHANNELS": {
1721
"description": "Comma-separated list of single guest channels to invite them to (leave blank for a normal, all-channel invite). In order to make this work, you have to have a paid account. You'll only be able to invite as many people as your number of paying members times 5.",
1822
"required": false

‎bin/slackin

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ program
1414
.option('-i, --interval <int>', 'How frequently (ms) to poll Slack [$SLACK_INTERVAL or 5000]', process.env.SLACK_INTERVAL || 5000)
1515
.option('-P, --path', 'Path to serve slackin under', '/')
1616
.option('-s, --silent', 'Do not print out warns or errors')
17+
.option('-C, --coc <coc>', 'Full URL to a CoC that needs to be agreed to')
1718
.option('-c, --css <file>', 'Full URL to a custom CSS file to use on the main page')
1819
.parse(process.argv);
1920

‎lib/assets/checkbox-checked.svg

+11
Loading

‎lib/assets/checkbox.png

115 Bytes
Loading

‎lib/assets/checkbox.svg

+12
Loading

‎lib/assets/client.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var request = superagent;
66
// elements
77
var select = body.querySelector('select');
88
var input = body.querySelector('input');
9+
var coc = body.querySelector('input[name=coc]');
910
var button = body.querySelector('button');
1011

1112
// remove loading state
@@ -18,7 +19,7 @@ body.addEventListener('submit', function(ev){
1819
button.className = '';
1920
button.innerHTML = 'Please Wait';
2021
var channel = select ? select.value : null;
21-
invite(channel, input.value, function(err){
22+
invite(channel, coc && coc.checked ? 1 : 0, input.value, function(err){
2223
if (err) {
2324
button.removeAttribute('disabled');
2425
button.className = 'error';
@@ -31,10 +32,11 @@ body.addEventListener('submit', function(ev){
3132
});
3233

3334

34-
function invite(channel, email, fn){
35+
function invite(channel, coc, email, fn){
3536
request
3637
.post(data.path + 'invite')
3738
.send({
39+
coc: coc,
3840
channel: channel,
3941
email: email
4042
})

‎lib/index.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export default function slackin({
2323
interval = 5000, // jshint ignore:line
2424
org,
2525
css,
26+
coc,
2627
path='/',
2728
channels,
2829
silent = false // jshint ignore:line
@@ -71,7 +72,7 @@ export default function slackin({
7172
dom('link rel="shortcut icon" href=https://slack.global.ssl.fastly.net/272a/img/icons/favicon-32.png'),
7273
css && dom('link rel=stylesheet', { href: css })
7374
),
74-
splash({ path, css, name, org, logo, channels, active, total })
75+
splash({ coc, path, css, name, org, logo, channels, active, total })
7576
);
7677
res.type('html');
7778
res.send(page.toHTML());
@@ -112,6 +113,12 @@ export default function slackin({
112113
.json({ msg: 'Invalid email' });
113114
}
114115

116+
if (coc && '1' != req.body.coc) {
117+
return res
118+
.status(400)
119+
.json({ msg: 'Agreement to CoC is mandatory' });
120+
}
121+
115122
invite({ token, org, email, channel: chanId }, err => {
116123
if (err) {
117124
return res
@@ -137,7 +144,7 @@ export default function slackin({
137144
let { name } = slack.org;
138145
let { active, total } = slack.users;
139146
if (!name) return res.send(404);
140-
let dom = splash({ path, name, channels, active, total, iframe: true });
147+
let dom = splash({ coc, path, name, channels, active, total, iframe: true });
141148
res.type('html');
142149
res.send(dom.toHTML());
143150
});

‎lib/splash.js

+51-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
import dom from 'vd';
33

4-
export default function splash({ path, name, org, logo, active, total, channels, iframe }){
4+
export default function splash({ path, name, org, coc, logo, active, total, channels, iframe }){
55
let div = dom('.splash',
66
!iframe && dom('.logos',
77
logo && dom('.logo.org'),
@@ -30,6 +30,14 @@ export default function splash({ path, name, org, logo, active, total, channels,
3030
),
3131
dom('input.form-item type=email placeholder=you@yourdomain.com '
3232
+ (!iframe ? 'autofocus' : '')),
33+
coc && dom('.coc',
34+
dom('label',
35+
dom('input type=checkbox name=coc value=1'),
36+
'I agree to the ',
37+
dom('a', { href: coc, target: '_blank', }, 'Code of Conduct'),
38+
'.'
39+
)
40+
),
3341
dom('button.loading', 'Get my Invite')
3442
),
3543
!iframe && dom('p.signin',
@@ -132,6 +140,48 @@ function style({ logo, active, iframe } = {}){
132140
}
133141
}
134142

143+
css.add('.coc', {
144+
'font-size': '12px',
145+
padding: '15px 0 5px',
146+
color: '#666'
147+
});
148+
149+
css.add('.coc label', {
150+
cursor: 'pointer'
151+
});
152+
153+
css.add('.coc input', {
154+
'appearance': 'none',
155+
'-webkit-appearance': 'none',
156+
border: 'none',
157+
'vertical-align': 'middle',
158+
margin: '0 5px 0 0',
159+
});
160+
161+
css.add('.coc input::after', {
162+
content: '""',
163+
display: 'inline-block',
164+
width: '15px',
165+
height: '15px',
166+
'vertical-align': 'middle',
167+
background: 'url(/assets/checkbox.svg)',
168+
cursor: 'pointer'
169+
});
170+
171+
css.add('.coc input:checked::after', {
172+
'background-position': 'right'
173+
});
174+
175+
css.add('.coc a', {
176+
color: '#666'
177+
});
178+
179+
css.add('.coc a:hover', {
180+
'background-color': '#666',
181+
'text-decoration': 'none',
182+
color: '#fff'
183+
});
184+
135185
css.add('p', {
136186
'font-size': iframe ? '12px' : '15px',
137187
'margin': iframe ? '0 0 5px' : '5px 0'

0 commit comments

Comments
 (0)
Please sign in to comment.