lita-hcadmin 0.3.3 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dbb668a3f1776c2b498ad15764a56d7f1b309347
4
- data.tar.gz: 27af7e8a66abb2e65e4ba40c38ab87688c28331a
3
+ metadata.gz: ea505de875b8f0e2b8e23e48b73f74dfdd841aca
4
+ data.tar.gz: 1723fa99de97712ef95809ead9eb19061c056360
5
5
  SHA512:
6
- metadata.gz: 7b888e6b7888f5d3412797d9cd28a33d293beb350861c9ec7b2eb72647ca5fc4ea918b05a99bb96b99c254033ef5f331bf5670346a810e0af543e3b3224fe27e
7
- data.tar.gz: 57975f9f90f363f2f24ddee9ababc163da5f785ee6b0280298c18a3b8efbb47087a93f40a695cbf6be0c384dda39b4feff423c7eb3220a921a0c60b4b78f91ed
6
+ metadata.gz: c4721968c8703aaf7a5dfb4c14a583ff05f3b40b5e88d04c46249775ae5b5c538461322ee6efee7fc81ee1fadb003a1d8a1175af021c818a2d36a751426c9d88
7
+ data.tar.gz: a4839fdf71f065c4ffe43ccab69f6be0b41b6033d9953cff4d1575be0b09d1e3229a223a405aed8b1aa1cdc8c120ca3d50beb846e92d82b19fad1940123c61f0
@@ -18,6 +18,7 @@ module Lita
18
18
  config :smtp_server
19
19
  config :allowed_domains
20
20
  config :room_change_admins, type: Array, required: false
21
+ config :user_change_admins, type: Array, required: false
21
22
  config :account_name, type: String, required: true
22
23
  config :email_domain_name, type: Array, required: true
23
24
  config :http_logging, type: [TrueClass, FalseClass], default: true, required: false
@@ -26,23 +27,23 @@ module Lita
26
27
  :identify_room_owner,
27
28
  help: { 'identify room owner ROOM_NAME' => 'Returns the mention name of the room owner.' })
28
29
 
29
- route(/(?:(?:identify hipchat admins))/i,
30
+ route(/identify hipchat admins/,
30
31
  :identify_hipchat_admins,
31
32
  help: { 'identify hipchat admins' => 'Returns the mention name of the HipChat Admins.' })
32
33
 
33
- route(/(?:(?:identify user count))/i,
34
+ route(/identify user count/,
34
35
  :identify_user_count,
35
36
  help: { 'identify user count' => 'Returns the count of users in the account.' })
36
37
 
37
- route(/(?:(?:identify room count))/i,
38
+ route(/identify room count/,
38
39
  :identify_room_count,
39
40
  help: { 'identify room count' => 'Returns the count of rooms in the account.' })
40
41
 
41
- route(/(?:(?:identify room change admins))/i,
42
+ route(/identify room change admins/,
42
43
  :identify_room_change_admins,
43
44
  help: { 'identify room change admins' => 'Returns a list of who can change room ownership' })
44
45
 
45
- route(/(?:(?:identify status))/i,
46
+ route(/identify status/,
46
47
  :identify_status,
47
48
  help: { 'identify status' => 'Returns the status of HipChat.' })
48
49
 
@@ -50,14 +51,18 @@ module Lita
50
51
  :hipchat_sponsor,
51
52
  help: { 'hipchat sponsor EMAIL ADDRESS' => 'Generates an invite to the person being sponsored. Use a valid email address' })
52
53
 
53
- route(/(?:(?:room owner change))\s+(.+)/i,
54
+ route(/((room owner change))\s+(.+)/i,
54
55
  :room_owner_change,
55
56
  help: { 'room owner change owner_mention_name room_name ' => 'When run as a room change admin, updates the room ownership' })
56
57
 
57
- route(/(?:(?:room unarchive))/i, # route(/(?:(?:room unarchive))\s+(.+)/i,
58
+ route(/((room unarchive))/i, # route(/(?:(?:room unarchive))\s+(.+)/i,
58
59
  :room_unarchive,
59
60
  help: { 'room unarchive room_name ' => 'When run as a room change admin, removes a room from archive' })
60
61
 
62
+ route(/((user activate))\s+(.+)/i,
63
+ :user_activate,
64
+ help: { 'user activate email name' => 'When run as a user admin, generates an invite to the email account' })
65
+
61
66
  def hipchat_sponsor(response)
62
67
  response.args.each do |r|
63
68
  next if 'sponsor'.include?(r)
@@ -140,38 +145,18 @@ module Lita
140
145
  end
141
146
 
142
147
  def identify_room_owner(response)
143
- room_name = nil
144
- reply_message = nil
145
- room_owner = nil
146
- time = Benchmark.measure do
147
- response.matches.each do |match|
148
- room_name = normalize_room_name(match[0])
149
- end
150
- # get room json
151
- response.reply 'Getting rooms ... one moment'
152
- room_data = fetch_rooms
153
-
154
- response.reply 'Getting room id ... another moment'
155
- room_id = id_from_name(room_name, parse(room_data[:body], 'rooms'))
156
-
157
- response.reply 'Getting the user name from the user ID ... almost there'
158
- room_owner = owner_id_from_room_id(room_id, parse(room_data[:body], 'rooms'))
159
-
160
- if room_owner.nil?
161
- reply_message = "Room #{room_name} apparently does not have an owner or I could not find a room with that name"
162
- elsif room_id.nil?
163
- reply_message = "Room #{room_name} apparently does not have an owner or I could not find a room with that name"
164
- end
148
+ @room_name = nil
149
+ @room_parse = nil
150
+ response.matches.each do |match|
151
+ @room_name = match[0]
165
152
  end
166
-
167
- if reply_message.nil?
168
- user_data = fetch_user(room_owner)
169
- owner_mention = owner_name_from_id(parse(user_data[:body], 'user'))
170
- reply_message = "The owner of #{room_name} is #{owner_mention}"
171
- response.reply reply_message
172
- else
173
- response.reply reply_message + " ( #{time.real.to_i} s. to respond )"
153
+ response.reply 'Getting rooms ... one moment'
154
+ room_info = fetch_data('v2', 'room', @room_name)
155
+ @room_parse = JSON.parse(room_info[:body])
156
+ if @room_parse.key?('error')
157
+ return response.reply @room_parse['error']['message']
174
158
  end
159
+ response.reply "The owner of #{@room_name} is #{@room_parse['owner']['name']}"
175
160
  end
176
161
 
177
162
  def parse(json, type)
@@ -191,29 +176,6 @@ module Lita
191
176
  json
192
177
  end
193
178
 
194
- def id_from_name(room_name, json)
195
- room_id = nil
196
- json.each do |j|
197
- next unless room_name == j['name'].to_s.downcase.strip
198
- room_id = j['room_id']
199
- end
200
- room_id
201
- end
202
-
203
- def owner_id_from_room_id(room_id, json)
204
- owner_id = nil
205
- json.each do |j|
206
- next unless room_id == j['room_id']
207
- owner_id = j['owner_user_id']
208
- end
209
- owner_id
210
- end
211
-
212
- def owner_name_from_id(json)
213
- user_name = json['mention_name']
214
- user_name
215
- end
216
-
217
179
  def room_owner_change(response) # Length check => owner: 1, change: 2, member_name: 3, room_name: 4, room_name can be multiple words!
218
180
  return response.reply 'You are not represented in the room owner change admin group' unless user_in_group(response.user.mention_name, room_change_admins) == true
219
181
  return response.reply "Wrong number of arguments; expected format of owner_name & room_name received arguments: #{response.args.values_at(2..response.args.length - 1)}" unless response.args.length > 3
@@ -264,8 +226,18 @@ module Lita
264
226
  json
265
227
  end
266
228
 
229
+ def user_activate(response)
230
+ # puts response.args
231
+ return response.reply 'First value should be a valid email address' unless valid_email?(response.args[0]) == 0
232
+ end
233
+
267
234
  private
268
235
 
236
+ def valid_email?(email_value)
237
+ valid_email_reg = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
238
+ email_value =~ valid_email_reg
239
+ end
240
+
269
241
  def user_data(user_name)
270
242
  user_check = JSON.parse(fetch_data('v2', 'user', user_name).to_json)
271
243
  user_details = JSON.parse(user_check['body'])
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-hcadmin"
3
- spec.version = "0.3.3"
3
+ spec.version = "0.3.5"
4
4
  spec.authors = ["Jason Walker"]
5
5
  spec.email = ["jason.walker@target.com"]
6
6
  spec.description = "HipChat admin plugin for Lita"
@@ -20,8 +20,8 @@ describe Lita::Handlers::Hcadmin, lita_handler: true do
20
20
  let(:mock_smtp) { mock('smtp') }
21
21
 
22
22
  let(:room_change_admin_member) { Lita::User.create(55, name: 'TestAdmin') }
23
+ let(:user_change_admin_member) { Lita::User.create(99, name: 'UserAdmin') }
23
24
  let(:regular_member) { Lita::User.create(66, name: 'RegularMember') }
24
-
25
25
  let(:fetch_api_data) { Hcadmin.fetch_data('v1', 'foo', 'bar') }
26
26
 
27
27
  before do
@@ -177,6 +177,30 @@ describe Lita::Handlers::Hcadmin, lita_handler: true do
177
177
  body: room_v2_json,
178
178
  headers: {}
179
179
  )
180
+ stub_request(:get, 'https://api.hipchat.com/v2/room/foobar?auth_token=abc&format=json')
181
+ .with(
182
+ headers: {
183
+ 'Accept' => 'application/json',
184
+ 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
185
+ 'Content-Type' => 'application/json',
186
+ 'User-Agent' => 'Faraday v0.9.2' })
187
+ .to_return(
188
+ status: 200,
189
+ body: room_v2_not_found,
190
+ headers: {}
191
+ )
192
+ stub_request(:get, 'https://api.hipchat.com/v2/room/Test%20Room%20@%20Company.com?auth_token=abc&format=json')
193
+ .with(
194
+ headers: {
195
+ 'Accept' => 'application/json',
196
+ 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
197
+ 'Content-Type' => 'application/json',
198
+ 'User-Agent' => 'Faraday v0.9.2' })
199
+ .to_return(
200
+ status: 200,
201
+ body: room_v2_json,
202
+ headers: {}
203
+ )
180
204
  end
181
205
 
182
206
  it 'routes the identify room owner command room name has spaces' do
@@ -223,6 +247,10 @@ describe Lita::Handlers::Hcadmin, lita_handler: true do
223
247
  is_expected.to route_command('room unarchive room_name').to(:room_unarchive)
224
248
  end
225
249
 
250
+ it 'routes user activate requests' do
251
+ is_expected.to route_command('user activate email_address name').to(:user_activate)
252
+ end
253
+
226
254
  describe '#hipchat_sponsor' do
227
255
  context 'validates the new account request is for a Target.com email address' do
228
256
  it 'rejects non-Target.com email addresses' do
@@ -338,23 +366,13 @@ describe Lita::Handlers::Hcadmin, lita_handler: true do
338
366
  describe '#identify_room_owner' do
339
367
  context 'getting the list of rooms' do
340
368
  it 'replies with the room_id for a real room name' do
341
- send_command('identify room owner floppy drive')
342
- expect(replies.last).to eq('The owner of floppy drive is AwesomeSauce')
343
- end
344
-
345
- it 'handles room names with numbers' do
346
- send_command('identify room owner f00_bar')
347
- expect(replies.last).to eq 'Room f00_bar apparently does not have an owner or I could not find a room with that name ( 0 s. to respond )'
369
+ send_command('identify room owner Test Room @ Company.com')
370
+ expect(replies.last).to eq('The owner of Test Room @ Company.com is Red Solo Cup')
348
371
  end
349
372
 
350
373
  it 'handles UCASE NAMES' do
351
- send_command('identify room owner FOO_BAR')
352
- expect(replies.last).to_not eq 'Sorry, no room found with that name FOO_BAR'
353
- end
354
-
355
- it 'handles NAMES-WITH-HYPHENS' do
356
- send_command('identify room owner NAMES-WITH-HYPHENS')
357
- expect(replies.last).to_not eq 'Sorry, no room found with that name NAMES-WITH-HYPHENS'
374
+ send_command('identify room owner foobar')
375
+ expect(replies.last).to eq "Room 'foobar' not found"
358
376
  end
359
377
  end
360
378
  end # end identify_room_owner
@@ -391,46 +409,40 @@ describe Lita::Handlers::Hcadmin, lita_handler: true do
391
409
  end # end fetch
392
410
 
393
411
  describe '#parse' do
394
- before(:each) do
395
- allow(described_class).to receive(:parse).with(room_json, 'rooms').and_return(JSON.parse(room_json))
396
- end
397
- let(:test_room_data) { described_class.parse(room_json, 'rooms') }
398
- let(:test_room_details) { test_room_data['rooms'] }
412
+ let(:test_room_data) { subject.parse(room_json, 'rooms') }
399
413
 
400
414
  context 'JSON data from parse should return a JSON object' do
401
415
  it 'gets a JSON object during parse' do
402
- expect(test_room_details.first['room_id']).to eq(31)
416
+ expect(test_room_data.first['room_id']).to eq(31)
403
417
  end
404
- end
405
- end
406
418
 
407
- describe '#owner_name_from_id' do
408
- before(:each) do
409
- allow(described_class).to receive(:owner_name_from_id).with(31, user_json).and_return('AwesomeSauce')
410
- end
411
- context 'an owner id can be translated to an owner name' do
412
- it 'gets the name of the room when presented a room ID' do
413
- expect(described_class.owner_name_from_id(31, user_json)).to eq 'AwesomeSauce'
419
+ it 'accepts parse method' do
420
+ expect(subject).to respond_to(:parse)
414
421
  end
415
422
  end
416
423
  end
417
424
 
418
- describe '#id_from_name' do
419
- before(:each) do
420
- allow(described_class).to receive(:id_from_name).with('floppy drive', room_json).and_return(31)
421
- end
422
-
423
- context 'returns the room_id from the room_name' do
424
- it 'does not error when getting the ID from name' do
425
- expect do
426
- described_class.id_from_name('floppy drive', room_json)
427
- end.to_not raise_error
428
- end
429
- it 'returns the room_id when given a room name' do
430
- expect(described_class.id_from_name('floppy drive', room_json)).to eq 31
431
- end
432
- end
433
- end
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
434
446
 
435
447
  describe '#identify_room_count' do
436
448
  context 'room count is returned when called' do
@@ -558,4 +570,16 @@ describe Lita::Handlers::Hcadmin, lita_handler: true do
558
570
  end
559
571
  end
560
572
  end
573
+
574
+ describe '#user_activate' do
575
+ context 'reactivates a person' do
576
+ 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 should be a valid email address')
579
+ end
580
+ it 'does stuff' do
581
+ send_command('user activate email@company.com')
582
+ end
583
+ end
584
+ end
561
585
  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.3.3
4
+ version: 0.3.5
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-04 00:00:00.000000000 Z
11
+ date: 2016-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita