lita-hcadmin 0.4.2 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +16 -0
- data/README.md +16 -0
- data/lib/lita/handlers/hcadmin.rb +22 -1
- data/lita-hcadmin.gemspec +1 -1
- data/spec/lita/handlers/hcadmin_spec.rb +56 -0
- metadata +23 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a305e9389b1108f8c4a4eaa5194562339a73c7de
|
4
|
+
data.tar.gz: f5bb648d9b55d44c9efde3787229d63cac9b65b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee4b47126ad575be01d78c78c262e3c561fefc4e3b75dc4abe14bc8b3fb097dc8d1bc04f069ad584e8bf55729e25f205ea222a0aa3f11d71e60cb74ba3a03070
|
7
|
+
data.tar.gz: 227e4c67e7e9185b2f6ad0c028136b17f424f4a17907a4a02409fbc30779d3cb2ba600a4077cf218f5308bc8e3f6e170d02622b87d0385ff69db439fa18cc45e
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
# lita-hcadmin
|
2
2
|
|
3
|
+
[0.4.4]
|
4
|
+
---------
|
5
|
+
- [desktophero] - User invite as a discrete route
|
6
|
+
|
7
|
+
[0.4.3]
|
8
|
+
---------
|
9
|
+
- [desktophero] - Not released: User activate now sends an invite through the HipChat V2 API
|
10
|
+
|
11
|
+
[0.4.2]
|
12
|
+
---------
|
13
|
+
- [desktophero] - User activation checks for array of approved domains from bot maintainers
|
14
|
+
|
15
|
+
[0.4.1]
|
16
|
+
---------
|
17
|
+
- [desktophero] - Not released as approved domains for emails were not checked for
|
18
|
+
|
3
19
|
[0.4.0]
|
4
20
|
---------
|
5
21
|
- [desktophero] - Activate user
|
data/README.md
CHANGED
@@ -174,6 +174,22 @@ user activate <in_user_email@company.com>
|
|
174
174
|
bot: That email is already in use.
|
175
175
|
```
|
176
176
|
|
177
|
+
### user invite
|
178
|
+
```
|
179
|
+
user invite <email_name@company.com>
|
180
|
+
bot: Invite sent to user with status code 200
|
181
|
+
```
|
182
|
+
|
183
|
+
A couple of checks:
|
184
|
+
```
|
185
|
+
user invite <bad_email@companyom>
|
186
|
+
bot: First value needs to be a valid email address
|
187
|
+
```
|
188
|
+
```
|
189
|
+
user invite <in_user_email@company.com>
|
190
|
+
bot: That email is already in use.
|
191
|
+
```
|
192
|
+
|
177
193
|
## TO-DOs
|
178
194
|
The Issues for this repo will be used to accept, collaborate, and complete `TO-DOs`
|
179
195
|
|
@@ -65,7 +65,11 @@ module Lita
|
|
65
65
|
|
66
66
|
route(/(?:(?:user activate))\s+(.+)/i,
|
67
67
|
:user_activate,
|
68
|
-
help: { 'user activate email@company' => 'When run as a user admin,
|
68
|
+
help: { 'user activate email@company' => 'When run as a user admin, creates an account' })
|
69
|
+
|
70
|
+
route(/(?:(?:user invite))\s+(.+)/i,
|
71
|
+
:user_invite,
|
72
|
+
help: { 'user invite email@company' => 'When run as a user admin, generates an invite to the email account' })
|
69
73
|
|
70
74
|
def hipchat_sponsor(response)
|
71
75
|
response.args.each do |r|
|
@@ -262,6 +266,23 @@ module Lita
|
|
262
266
|
response.reply "Added user with status code #{user_response.status}"
|
263
267
|
end
|
264
268
|
|
269
|
+
def user_invite(response)
|
270
|
+
return response.reply 'You are not represented in the USER admin group' unless user_in_group(response.user.mention_name, user_change_admins) == true
|
271
|
+
user_data = user_account_parse(response.matches)
|
272
|
+
user_email = user_data[0]
|
273
|
+
user_name = username_from_email(user_email)
|
274
|
+
return response.reply 'First value needs to be a valid email address' unless valid_email?(user_email) == 0
|
275
|
+
unless email_domain_name.include? domain_from_email(user_email)
|
276
|
+
return response.reply "That email address is not in the approved list to activate. Approved email accounts: #{email_domain_name}"
|
277
|
+
end
|
278
|
+
user_data_check = user_exists?(user_email)
|
279
|
+
return response.reply 'That email is already in use but in a different HipChat account.' if user_data_check[:status] == 409
|
280
|
+
return response.reply 'That email is already an active user in this HipChat account' if user_data_check[:status] == 200
|
281
|
+
return response.reply "I did not understand the status code from HipChat: #{user_data_check[:status]}" unless user_data_check[:status] == 404
|
282
|
+
invite_response = http_post("https://api.hipchat.com/v2/invite/user?auth_token=#{v2_admin_token}&format=json", name: user_name, email: user_email)
|
283
|
+
response.reply "Invite to user sent with status code #{invite_response.status}"
|
284
|
+
end
|
285
|
+
|
265
286
|
private
|
266
287
|
|
267
288
|
def domain_from_email(email)
|
data/lita-hcadmin.gemspec
CHANGED
@@ -195,6 +195,34 @@ describe Lita::Handlers::Hcadmin, lita_handler: true do
|
|
195
195
|
headers: {}
|
196
196
|
)
|
197
197
|
|
198
|
+
stub_request(:post, 'https://api.hipchat.com/v2/invite/user?auth_token=abc&format=json')
|
199
|
+
.with(
|
200
|
+
body: "{\"name\":\"email.name\",\"email\":\"email.name@company.com\"}", # rubocop:disable Style/StringLiterals
|
201
|
+
headers: {
|
202
|
+
'Accept' => 'application/json',
|
203
|
+
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
204
|
+
'Content-Type' => 'application/json',
|
205
|
+
'User-Agent' => 'Faraday v0.9.2' })
|
206
|
+
.to_return(
|
207
|
+
status: 200,
|
208
|
+
body: '',
|
209
|
+
headers: {}
|
210
|
+
)
|
211
|
+
|
212
|
+
stub_request(:post, 'https://api.hipchat.com/v2/invite/user?auth_token=abc&format=json')
|
213
|
+
.with(
|
214
|
+
body: "{\"name\":\"new.person\",\"email\":\"new.person@company.com\"}", # rubocop:disable Style/StringLiterals
|
215
|
+
headers: {
|
216
|
+
'Accept' => 'application/json',
|
217
|
+
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
218
|
+
'Content-Type' => 'application/json',
|
219
|
+
'User-Agent' => 'Faraday v0.9.2' })
|
220
|
+
.to_return(
|
221
|
+
status: 200,
|
222
|
+
body: '',
|
223
|
+
headers: {}
|
224
|
+
)
|
225
|
+
|
198
226
|
stub_request(:get, 'https://api.hipchat.com/v2/room/real%20room?auth_token=abc&format=json')
|
199
227
|
.with(
|
200
228
|
headers: {
|
@@ -298,6 +326,10 @@ describe Lita::Handlers::Hcadmin, lita_handler: true do
|
|
298
326
|
is_expected.to route_command('user activate email_address name').to(:user_activate)
|
299
327
|
end
|
300
328
|
|
329
|
+
it 'routes user invite requests' do
|
330
|
+
is_expected.to route_command('user invite email_address name').to(:user_invite)
|
331
|
+
end
|
332
|
+
|
301
333
|
describe '#hipchat_sponsor' do
|
302
334
|
context 'validates the new account request is for a company.com email address' do
|
303
335
|
it 'rejects non-company.com email addresses' do
|
@@ -619,6 +651,30 @@ describe Lita::Handlers::Hcadmin, lita_handler: true do
|
|
619
651
|
end
|
620
652
|
end
|
621
653
|
|
654
|
+
describe '#user_invite' do
|
655
|
+
context 'invites a person' do
|
656
|
+
it 'blocks an activation if requestor is not a user admin' do
|
657
|
+
send_command('user invite email.name@companycom', as: regular_member)
|
658
|
+
expect(replies.last).to include('You are not represented in the USER admin group')
|
659
|
+
end
|
660
|
+
|
661
|
+
it 'catches if the user does not use a real email address' do
|
662
|
+
send_command('user invite email.name@companycom', as: user_change_admin_member)
|
663
|
+
expect(replies.last).to include('First value needs to be a valid email address')
|
664
|
+
end
|
665
|
+
|
666
|
+
it 'rejects non-company.com email addresses' do
|
667
|
+
send_command('user invite dummy@gmail.com', as: user_change_admin_member)
|
668
|
+
expect(replies.last).to eq('That email address is not in the approved list to activate. Approved email accounts: ["@company.com", "@network.net"]')
|
669
|
+
end
|
670
|
+
|
671
|
+
it 'adds a user if the inputs are sane' do
|
672
|
+
send_command('user invite email.name@company.com Test Account', as: user_change_admin_member)
|
673
|
+
expect(replies.last).to include('Invite to user sent with status code 200')
|
674
|
+
end
|
675
|
+
end
|
676
|
+
end
|
677
|
+
|
622
678
|
context 'the user account already exists' do
|
623
679
|
let(:user_v2_already_exists) { File.read(File.join('spec', 'fixtures', 'user_v2_already_exists.json')) }
|
624
680
|
before do
|
metadata
CHANGED
@@ -1,111 +1,111 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-hcadmin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Walker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '4.3'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '4.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.3'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: pry-byebug
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rack-test
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rspec
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - '>='
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: 3.0.0
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - '>='
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 3.0.0
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rest-client
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - '>='
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - '>='
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
description: HipChat admin plugin for Lita
|
@@ -115,10 +115,10 @@ executables: []
|
|
115
115
|
extensions: []
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
|
-
-
|
119
|
-
-
|
120
|
-
-
|
121
|
-
-
|
118
|
+
- .gitignore
|
119
|
+
- .rspec
|
120
|
+
- .rubocop.yml
|
121
|
+
- .travis.yml
|
122
122
|
- CHANGELOG.md
|
123
123
|
- Gemfile
|
124
124
|
- LICENSE.md
|
@@ -155,17 +155,17 @@ require_paths:
|
|
155
155
|
- lib
|
156
156
|
required_ruby_version: !ruby/object:Gem::Requirement
|
157
157
|
requirements:
|
158
|
-
- -
|
158
|
+
- - '>='
|
159
159
|
- !ruby/object:Gem::Version
|
160
160
|
version: '0'
|
161
161
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
162
162
|
requirements:
|
163
|
-
- -
|
163
|
+
- - '>='
|
164
164
|
- !ruby/object:Gem::Version
|
165
165
|
version: '0'
|
166
166
|
requirements: []
|
167
167
|
rubyforge_project:
|
168
|
-
rubygems_version: 2.
|
168
|
+
rubygems_version: 2.0.14.1
|
169
169
|
signing_key:
|
170
170
|
specification_version: 4
|
171
171
|
summary: Allow your HipChat admins to interact with the HipChat APIs
|
@@ -185,4 +185,3 @@ test_files:
|
|
185
185
|
- spec/fixtures/v2_user_not_found.json
|
186
186
|
- spec/lita/handlers/hcadmin_spec.rb
|
187
187
|
- spec/spec_helper.rb
|
188
|
-
has_rdoc:
|