lita-hcadmin 0.3.5 → 0.4.2
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +6 -0
- data/.travis.yml +1 -0
- data/CHANGELOG.md +17 -0
- data/Gemfile +1 -0
- data/README.md +25 -0
- data/lib/lita/handlers/hcadmin.rb +68 -4
- data/lita-hcadmin.gemspec +1 -1
- data/spec/fixtures/user_v2_already_exists.json +7 -0
- data/spec/lita/handlers/hcadmin_spec.rb +124 -28
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e35066ec0936361e47aba8dced07c20c011741d
|
4
|
+
data.tar.gz: bf0d87dbc41f183bf67a3fb14c07aebfedd2009c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 09e7acd16ce9e3de0176420d127f75cd5c52450cd1ffc17ca4e1782c9c232e589de6e0a270bc711004047fed7bb4b453fb4e71318419162a8037652ab1f3a204
|
7
|
+
data.tar.gz: d00d1bc5047e1af4bfa5483c807e3a62c2e9dab975604fa4023941747dbac87ab626d1d8100927aa700e21f11cea7720617d690b9e95ac6d665c22728db937d7
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,22 @@
|
|
1
1
|
# lita-hcadmin
|
2
2
|
|
3
|
+
[0.4.0]
|
4
|
+
---------
|
5
|
+
- [desktophero] - Activate user
|
6
|
+
- [desktophero] - Show user admin list
|
7
|
+
|
8
|
+
[0.3.5]
|
9
|
+
---------
|
10
|
+
- [desktophero] - Small updates to existing functions:
|
11
|
+
* [desktophero] - Identify room owner now uses HipChat V2 API
|
12
|
+
* Remove wild cards from some of the routes
|
13
|
+
* Cleaned up needless code for room owner lookup
|
14
|
+
* Leveled up some tests
|
15
|
+
|
16
|
+
[0.3.4]
|
17
|
+
---------
|
18
|
+
- [desktophero] - Not released. Found url encoding issue for room owner identify route
|
19
|
+
|
3
20
|
[0.3.3]
|
4
21
|
---------
|
5
22
|
- [desktophero] - Fix unarchive logic for multi-word names
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -148,6 +148,31 @@ room owner change RealName FakeRoom
|
|
148
148
|
bot: Uh-oh, 404 returned! The room FakeRoom not found
|
149
149
|
```
|
150
150
|
|
151
|
+
### identify user change admins
|
152
|
+
```
|
153
|
+
identify user change admins
|
154
|
+
bot: Users who can change user details
|
155
|
+
MentionName1
|
156
|
+
MentionName2
|
157
|
+
```
|
158
|
+
|
159
|
+
The list of names is defined in `Lita.config.handlers.hcadmin.user_change_admins` as an array of MentionNames
|
160
|
+
|
161
|
+
### user activate
|
162
|
+
```
|
163
|
+
user activate <email_name@company.com>
|
164
|
+
bot: Added user with status code 201
|
165
|
+
```
|
166
|
+
|
167
|
+
A couple of checks:
|
168
|
+
```
|
169
|
+
user activate <bad_email@companyom>
|
170
|
+
bot: First value needs to be a valid email address
|
171
|
+
```
|
172
|
+
```
|
173
|
+
user activate <in_user_email@company.com>
|
174
|
+
bot: That email is already in use.
|
175
|
+
```
|
151
176
|
|
152
177
|
## TO-DOs
|
153
178
|
The Issues for this repo will be used to accept, collaborate, and complete `TO-DOs`
|
@@ -43,6 +43,10 @@ module Lita
|
|
43
43
|
:identify_room_change_admins,
|
44
44
|
help: { 'identify room change admins' => 'Returns a list of who can change room ownership' })
|
45
45
|
|
46
|
+
route(/identify user change admins/,
|
47
|
+
:identify_user_change_admins,
|
48
|
+
help: { 'identify user change admins' => 'Returns a list of who can change user accounts' })
|
49
|
+
|
46
50
|
route(/identify status/,
|
47
51
|
:identify_status,
|
48
52
|
help: { 'identify status' => 'Returns the status of HipChat.' })
|
@@ -59,9 +63,9 @@ module Lita
|
|
59
63
|
:room_unarchive,
|
60
64
|
help: { 'room unarchive room_name ' => 'When run as a room change admin, removes a room from archive' })
|
61
65
|
|
62
|
-
route(/((user activate))\s+(.+)/i,
|
66
|
+
route(/(?:(?:user activate))\s+(.+)/i,
|
63
67
|
:user_activate,
|
64
|
-
help: { 'user activate email
|
68
|
+
help: { 'user activate email@company' => 'When run as a user admin, generates an invite to the email account' })
|
65
69
|
|
66
70
|
def hipchat_sponsor(response)
|
67
71
|
response.args.each do |r|
|
@@ -116,6 +120,20 @@ module Lita
|
|
116
120
|
response.reply "room change admins: #{room_change_admins.length} found ( #{time.real.to_i} s. to respond )"
|
117
121
|
end
|
118
122
|
|
123
|
+
def identify_user_change_admins(response)
|
124
|
+
response.reply 'Users who can change user details:'
|
125
|
+
time = Benchmark.measure do
|
126
|
+
if user_change_admins.first.to_s.empty? # rubocop:disable Style/GuardClause
|
127
|
+
return response.reply 'User change admins: None found from config'
|
128
|
+
else
|
129
|
+
user_change_admins.each do |a|
|
130
|
+
response.reply a.to_s
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
response.reply "user change admins: #{user_change_admins.length} found ( #{time.real.to_i} s. to respond )"
|
135
|
+
end
|
136
|
+
|
119
137
|
def identify_room_count(response)
|
120
138
|
room_count = ''
|
121
139
|
time = Benchmark.measure do
|
@@ -227,12 +245,38 @@ module Lita
|
|
227
245
|
end
|
228
246
|
|
229
247
|
def user_activate(response)
|
230
|
-
|
231
|
-
|
248
|
+
return response.reply 'You are not represented in the USER admin group' unless user_in_group(response.user.mention_name, user_change_admins) == true
|
249
|
+
user_data = user_account_parse(response.matches)
|
250
|
+
user_email = user_data[0]
|
251
|
+
user_name = username_from_email(user_email)
|
252
|
+
return response.reply 'First value needs to be a valid email address' unless valid_email?(user_email) == 0
|
253
|
+
unless email_domain_name.include? domain_from_email(user_email)
|
254
|
+
return response.reply "That email address is not in the approved list to activate. Approved email accounts: #{email_domain_name}"
|
255
|
+
end
|
256
|
+
user_data_check = user_exists?(user_email)
|
257
|
+
return response.reply 'That email is already in use but in a different HipChat account.' if user_data_check[:status] == 409
|
258
|
+
return response.reply 'That email is already an active user in this HipChat account' if user_data_check[:status] == 200
|
259
|
+
return response.reply "I did not understand the status code from HipChat: #{user_data_check[:status]}" unless user_data_check[:status] == 404
|
260
|
+
user_response = http_post("https://api.hipchat.com/v2/user?auth_token=#{v2_admin_token}&format=json", name: user_name, email: user_email)
|
261
|
+
return response.reply "Error while trying to add user: #{user_response.status} -- #{user_response.body}" unless user_response.status == 201
|
262
|
+
response.reply "Added user with status code #{user_response.status}"
|
232
263
|
end
|
233
264
|
|
234
265
|
private
|
235
266
|
|
267
|
+
def domain_from_email(email)
|
268
|
+
at = email.index('@')
|
269
|
+
email[at..-1]
|
270
|
+
end
|
271
|
+
|
272
|
+
def user_exists?(email)
|
273
|
+
fetch_data('v2', 'user', email)
|
274
|
+
end
|
275
|
+
|
276
|
+
def user_account_parse(data)
|
277
|
+
data[0][0].split(' ')
|
278
|
+
end
|
279
|
+
|
236
280
|
def valid_email?(email_value)
|
237
281
|
valid_email_reg = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
|
238
282
|
email_value =~ valid_email_reg
|
@@ -263,6 +307,10 @@ module Lita
|
|
263
307
|
email_name
|
264
308
|
end
|
265
309
|
|
310
|
+
def camelize_username(data)
|
311
|
+
data.split('.').collect(&:capitalize).join
|
312
|
+
end
|
313
|
+
|
266
314
|
def fetch_rooms # full list
|
267
315
|
url = "https://api.hipchat.com/v1/rooms/list?auth_token=#{v1_admin_token}&format=json"
|
268
316
|
proxy = http_proxy || nil
|
@@ -345,6 +393,10 @@ module Lita
|
|
345
393
|
config.room_change_admins
|
346
394
|
end
|
347
395
|
|
396
|
+
def user_change_admins
|
397
|
+
config.user_change_admins
|
398
|
+
end
|
399
|
+
|
348
400
|
def normalize_room_name(room_name)
|
349
401
|
room_name = room_name.to_s.downcase.strip
|
350
402
|
room_name
|
@@ -398,6 +450,18 @@ END_OF_EMAIL
|
|
398
450
|
response
|
399
451
|
end
|
400
452
|
|
453
|
+
def http_post(url, payload, _proxy = {})
|
454
|
+
conn = http_conn(url)
|
455
|
+
response = conn.post do |c|
|
456
|
+
c.options.timeout = 60
|
457
|
+
c.options.open_timeout = 60
|
458
|
+
c.headers['Content-Type'] = 'application/json'
|
459
|
+
c.headers['Accept'] = 'application/json'
|
460
|
+
c.body = payload.to_json
|
461
|
+
end
|
462
|
+
response
|
463
|
+
end
|
464
|
+
|
401
465
|
def http_conn(url)
|
402
466
|
@http_conn = Faraday.new(url: url) do |h|
|
403
467
|
h.request :url_encoded
|
data/lita-hcadmin.gemspec
CHANGED
@@ -33,6 +33,7 @@ describe Lita::Handlers::Hcadmin, lita_handler: true do
|
|
33
33
|
config.handlers.hcadmin.email_dist_list = 'blahblah@company.com'
|
34
34
|
config.handlers.hcadmin.smtp_server = 'smtp.mailserverstuffandthings.com'
|
35
35
|
config.handlers.hcadmin.room_change_admins = ['TestAdmin', 'AnotherAdmin'] # rubocop:disable Style/WordArray
|
36
|
+
config.handlers.hcadmin.user_change_admins = ['UserAdmin', 'AnotherAdmin'] # rubocop:disable Style/WordArray
|
36
37
|
config.handlers.hcadmin.account_name = 'TestHipChatAccount'
|
37
38
|
config.handlers.hcadmin.email_domain_name = ['@company.com', '@network.net']
|
38
39
|
config.handlers.hcadmin.http_logging = false
|
@@ -165,6 +166,35 @@ describe Lita::Handlers::Hcadmin, lita_handler: true do
|
|
165
166
|
body: '',
|
166
167
|
headers: {}
|
167
168
|
)
|
169
|
+
|
170
|
+
stub_request(:post, 'https://api.hipchat.com/v2/user?auth_token=abc&format=json')
|
171
|
+
.with(
|
172
|
+
body: "{\"name\":\"new.person\",\"email\":\"new.person@company.com\"}", # rubocop:disable Style/StringLiterals
|
173
|
+
headers: {
|
174
|
+
'Accept' => 'application/json',
|
175
|
+
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
176
|
+
'Content-Type' => 'application/json',
|
177
|
+
'User-Agent' => 'Faraday v0.9.2' })
|
178
|
+
.to_return(
|
179
|
+
status: 201,
|
180
|
+
body: '',
|
181
|
+
headers: {}
|
182
|
+
)
|
183
|
+
|
184
|
+
stub_request(:post, 'https://api.hipchat.com/v2/user?auth_token=abc&format=json')
|
185
|
+
.with(
|
186
|
+
body: "{\"name\":\"email.name\",\"email\":\"email.name@company.com\"}", # rubocop:disable Style/StringLiterals
|
187
|
+
headers: {
|
188
|
+
'Accept' => 'application/json',
|
189
|
+
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
190
|
+
'Content-Type' => 'application/json',
|
191
|
+
'User-Agent' => 'Faraday v0.9.2' })
|
192
|
+
.to_return(
|
193
|
+
status: 201,
|
194
|
+
body: '',
|
195
|
+
headers: {}
|
196
|
+
)
|
197
|
+
|
168
198
|
stub_request(:get, 'https://api.hipchat.com/v2/room/real%20room?auth_token=abc&format=json')
|
169
199
|
.with(
|
170
200
|
headers: {
|
@@ -177,6 +207,7 @@ describe Lita::Handlers::Hcadmin, lita_handler: true do
|
|
177
207
|
body: room_v2_json,
|
178
208
|
headers: {}
|
179
209
|
)
|
210
|
+
|
180
211
|
stub_request(:get, 'https://api.hipchat.com/v2/room/foobar?auth_token=abc&format=json')
|
181
212
|
.with(
|
182
213
|
headers: {
|
@@ -201,6 +232,18 @@ describe Lita::Handlers::Hcadmin, lita_handler: true do
|
|
201
232
|
body: room_v2_json,
|
202
233
|
headers: {}
|
203
234
|
)
|
235
|
+
stub_request(:get, 'https://api.hipchat.com/v2/user/email.name@company.com?auth_token=abc&format=json')
|
236
|
+
.with(
|
237
|
+
headers: {
|
238
|
+
'Accept' => 'application/json',
|
239
|
+
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
240
|
+
'Content-Type' => 'application/json',
|
241
|
+
'User-Agent' => 'Faraday v0.9.2' })
|
242
|
+
.to_return(
|
243
|
+
status: 404,
|
244
|
+
body: user_v2_not_found,
|
245
|
+
headers: {}
|
246
|
+
)
|
204
247
|
end
|
205
248
|
|
206
249
|
it 'routes the identify room owner command room name has spaces' do
|
@@ -239,6 +282,10 @@ describe Lita::Handlers::Hcadmin, lita_handler: true do
|
|
239
282
|
is_expected.to route_command('identify room change admins').to(:identify_room_change_admins)
|
240
283
|
end
|
241
284
|
|
285
|
+
it 'routes user change admin requests' do
|
286
|
+
is_expected.to route_command('identify user change admins').to(:identify_user_change_admins)
|
287
|
+
end
|
288
|
+
|
242
289
|
it 'routes room owner change requests' do
|
243
290
|
is_expected.to route_command('room owner change mention_name room_name').to(:room_owner_change)
|
244
291
|
end
|
@@ -252,8 +299,8 @@ describe Lita::Handlers::Hcadmin, lita_handler: true do
|
|
252
299
|
end
|
253
300
|
|
254
301
|
describe '#hipchat_sponsor' do
|
255
|
-
context 'validates the new account request is for a
|
256
|
-
it 'rejects non-
|
302
|
+
context 'validates the new account request is for a company.com email address' do
|
303
|
+
it 'rejects non-company.com email addresses' do
|
257
304
|
send_command('hipchat sponsor dummy@gmail.com')
|
258
305
|
expect(replies.last).to eq('The email address has to be one of: ["@company.com", "@network.net"]')
|
259
306
|
end
|
@@ -422,28 +469,6 @@ describe Lita::Handlers::Hcadmin, lita_handler: true do
|
|
422
469
|
end
|
423
470
|
end
|
424
471
|
|
425
|
-
# describe '#owner_name_from_id' do
|
426
|
-
# # before(:each) do
|
427
|
-
# # allow(described_class).to receive(:owner_name_from_id).with(31, user_json).and_return('AwesomeSauce')
|
428
|
-
# # end
|
429
|
-
# let(:user_mention_name) { subject.owner_name_from_id(user_json) }
|
430
|
-
# context 'an owner id can be translated to an owner name' do
|
431
|
-
# it 'returns the mention name field from JSON data' do
|
432
|
-
# # expect(described_class.owner_name_from_id(31, user_json)).to eq 'AwesomeSauce'
|
433
|
-
# expect(user_mention_name).to eq 'AwesomeSauce'
|
434
|
-
# end
|
435
|
-
# end
|
436
|
-
# end
|
437
|
-
#
|
438
|
-
# describe '#id_from_name' do
|
439
|
-
# let(:room_search) { subject.id_from_name('floppy drive', room_json) }
|
440
|
-
# context 'returns the room_id from the room_name' do
|
441
|
-
# it 'does not error when getting the ID from name' do
|
442
|
-
# expect(room_search).to eq 31
|
443
|
-
# end
|
444
|
-
# end
|
445
|
-
# end
|
446
|
-
|
447
472
|
describe '#identify_room_count' do
|
448
473
|
context 'room count is returned when called' do
|
449
474
|
it 'returns the number of rooms when requested' do
|
@@ -573,13 +598,84 @@ describe Lita::Handlers::Hcadmin, lita_handler: true do
|
|
573
598
|
|
574
599
|
describe '#user_activate' do
|
575
600
|
context 'reactivates a person' do
|
601
|
+
it 'blocks an activation if requestor is not a user admin' do
|
602
|
+
send_command('user activate email.name@companycom', as: regular_member)
|
603
|
+
expect(replies.last).to include('You are not represented in the USER admin group')
|
604
|
+
end
|
605
|
+
|
576
606
|
it 'catches if the user does not use a real email address' do
|
577
|
-
send_command('user activate email@companycom')
|
578
|
-
expect(replies.last).to include('First value
|
607
|
+
send_command('user activate email.name@companycom', as: user_change_admin_member)
|
608
|
+
expect(replies.last).to include('First value needs to be a valid email address')
|
579
609
|
end
|
580
|
-
|
581
|
-
|
610
|
+
|
611
|
+
it 'rejects non-company.com email addresses' do
|
612
|
+
send_command('user activate dummy@gmail.com', as: user_change_admin_member)
|
613
|
+
expect(replies.last).to eq('That email address is not in the approved list to activate. Approved email accounts: ["@company.com", "@network.net"]')
|
614
|
+
end
|
615
|
+
|
616
|
+
it 'adds a user if the inputs are sane' do
|
617
|
+
send_command('user activate email.name@company.com Test Account', as: user_change_admin_member)
|
618
|
+
expect(replies.last).to include('Added user with status code 201')
|
619
|
+
end
|
620
|
+
end
|
621
|
+
|
622
|
+
context 'the user account already exists' do
|
623
|
+
let(:user_v2_already_exists) { File.read(File.join('spec', 'fixtures', 'user_v2_already_exists.json')) }
|
624
|
+
before do
|
625
|
+
stub_request(:get, 'https://api.hipchat.com/v2/user/existing.person@company.com?auth_token=abc&format=json')
|
626
|
+
.with(
|
627
|
+
headers: {
|
628
|
+
'Accept' => 'application/json',
|
629
|
+
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
630
|
+
'Content-Type' => 'application/json',
|
631
|
+
'User-Agent' => 'Faraday v0.9.2' })
|
632
|
+
.to_return(
|
633
|
+
status: 409,
|
634
|
+
body: user_v2_already_exists,
|
635
|
+
headers: {}
|
636
|
+
)
|
637
|
+
end
|
638
|
+
it 'returns a 409 when the account exists in another account' do
|
639
|
+
send_command('user activate existing.person@company.com', as: user_change_admin_member)
|
640
|
+
expect(replies.last).to eq 'That email is already in use but in a different HipChat account.'
|
641
|
+
end
|
642
|
+
end
|
643
|
+
context 'the user account already exists' do
|
644
|
+
let(:user_v2_new) { File.read(File.join('spec', 'fixtures', 'v2_user_not_found.json')) }
|
645
|
+
before do
|
646
|
+
stub_request(:get, 'https://api.hipchat.com/v2/user/new.person@company.com?auth_token=abc&format=json')
|
647
|
+
.with(
|
648
|
+
headers: {
|
649
|
+
'Accept' => 'application/json',
|
650
|
+
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
651
|
+
'Content-Type' => 'application/json',
|
652
|
+
'User-Agent' => 'Faraday v0.9.2' })
|
653
|
+
.to_return(
|
654
|
+
status: 404,
|
655
|
+
body: user_v2_not_found,
|
656
|
+
headers: {}
|
657
|
+
)
|
658
|
+
end
|
659
|
+
it 'validates a new account is legit' do
|
660
|
+
send_command('user activate new.person@company.com', as: user_change_admin_member)
|
661
|
+
expect(replies.last).to eq 'Added user with status code 201'
|
582
662
|
end
|
583
663
|
end
|
584
664
|
end
|
665
|
+
|
666
|
+
describe '#identify_user_change_admins' do
|
667
|
+
context 'returns the user change admins' do
|
668
|
+
it 'names are returned' do
|
669
|
+
send_command('identify user change admins')
|
670
|
+
expect(replies.last).to include('user change admins')
|
671
|
+
end
|
672
|
+
end
|
673
|
+
|
674
|
+
context 'shows UserAdmin name from hcadmin.config' do
|
675
|
+
it 'shows the UserAdmin was returned' do
|
676
|
+
send_command('identify user change admins')
|
677
|
+
expect(replies).to include('UserAdmin')
|
678
|
+
end
|
679
|
+
end
|
680
|
+
end # end room change admins
|
585
681
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-hcadmin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.2
|
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-03
|
11
|
+
date: 2016-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|
@@ -134,6 +134,7 @@ files:
|
|
134
134
|
- spec/fixtures/stats.json
|
135
135
|
- spec/fixtures/status.json
|
136
136
|
- spec/fixtures/user_data.json
|
137
|
+
- spec/fixtures/user_v2_already_exists.json
|
137
138
|
- spec/fixtures/user_v2_data.json
|
138
139
|
- spec/fixtures/user_v2_notreal_email.json
|
139
140
|
- spec/fixtures/users_data.json
|
@@ -175,6 +176,7 @@ test_files:
|
|
175
176
|
- spec/fixtures/stats.json
|
176
177
|
- spec/fixtures/status.json
|
177
178
|
- spec/fixtures/user_data.json
|
179
|
+
- spec/fixtures/user_v2_already_exists.json
|
178
180
|
- spec/fixtures/user_v2_data.json
|
179
181
|
- spec/fixtures/user_v2_notreal_email.json
|
180
182
|
- spec/fixtures/users_data.json
|