cafmal 0.22.0 → 0.23.0

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: 7538cbd3446a01fa4cba36d7b6b6b0d074f7d2e7
4
- data.tar.gz: 58f9df9e4247c5192e55f3779d8c763454e0d26f
3
+ metadata.gz: 2d6712ce334fc95292bc85613b620f54a5ae86a2
4
+ data.tar.gz: 696029cbc24ad382f20074fb4ff8b68a70c7f5d4
5
5
  SHA512:
6
- metadata.gz: 88227c3a8fa2657f990a8d2819634ccf46f9a934c15040d801ed8e8eeb6d024d4c8ce98b493f90529df634ce02fea5a28c8dc267bd13f97cb7a78ff9f51a718e
7
- data.tar.gz: 3dd60239cd1a18b264a182e4a6d2d2a9e534e355d8c048c3a4d155b8eadb69c4333baa28baa1fd620cef099f01063ecc8e905fa3753f8bd3f304421036271f85
6
+ metadata.gz: 0bcbe576328a29f763cd5adaf681e9145e7161848566d83ee577a09203f9d58b924d8d5f81e48ca27f2bf4a4abaeda4f4a954ece956c9d410a18ada34180b96e
7
+ data.tar.gz: 02e7fcad6e7c1e140716e0d383cc48106f51a9225a0b62fd10ef245a11d39b95e15a3db9d2684ec05fb7a4e5a2eea5d2e5325040d171e00c74307d1f646a252d
data/lib/cafmal/auth.rb CHANGED
@@ -38,7 +38,7 @@ module Cafmal
38
38
  @decoded_token['header'] = JSON.parse(Base64.decode64(@token.split('.')[0]))
39
39
  @decoded_token['payload'] = JSON.parse(Base64.decode64(@token.split('.')[1]))
40
40
 
41
- if (@decoded_token['payload']['role'] == 'user' || @decoded_token['payload']['role'] == 'admin')
41
+ if (@decoded_token['payload']['role'] != 'worker' && @decoded_token['payload']['role'] != 'alerter')
42
42
  team_id = JSON.parse(Cafmal::User.new(@cafmal_api_url, @token).show(@decoded_token['payload']['sub']))["team_id"]
43
43
  event = Cafmal::Event.new(@cafmal_api_url, @token)
44
44
  event.create({name: 'user.login', message: "#{email} has logged in.", kind: 'login', severity: 'info', team_id: team_id})
@@ -52,31 +52,52 @@ module Cafmal
52
52
 
53
53
  # we supply the token here, so web does not have to cache the auth obj
54
54
  def logout(token)
55
- unless token.nil?
56
- headers = {"Content-Type" => "application/json", "Authorization" => "Bearer #{token}"}
55
+ headers = {"Content-Type" => "application/json", "Authorization" => "Bearer #{token}"}
57
56
 
58
- decoded_token = {}
59
- decoded_token['header'] = JSON.parse(Base64.decode64(token.split('.')[0]))
60
- decoded_token['payload'] = JSON.parse(Base64.decode64(token.split('.')[1]))
57
+ decoded_token = {}
58
+ decoded_token['header'] = JSON.parse(Base64.decode64(token.split('.')[0]))
59
+ decoded_token['payload'] = JSON.parse(Base64.decode64(token.split('.')[1]))
61
60
 
62
- user = JSON.parse(Cafmal::User.new(@cafmal_api_url, token).show(decoded_token['payload']['sub']))
63
- team_id = user["team_id"]
64
- email = user["email"]
61
+ user = JSON.parse(Cafmal::User.new(@cafmal_api_url, token).show(decoded_token['payload']['sub']))
62
+ team_id = user["team_id"]
63
+ email = user["email"]
65
64
 
66
- #@TODO if you are the last logged in user, unsilence your team alerts
65
+ #@TODO if you are the last logged in user, unsilence your team alerts
67
66
 
68
- # kind has to be login, as it's a label of events
69
- event_id = JSON.parse(Cafmal::Event.new(@cafmal_api_url, token).create({name: 'user.logout', message: "#{email} has logged out.", kind: 'login', severity: 'info', team_id: team_id}))
67
+ # kind has to be login, as it's a label of events
68
+ event_id = JSON.parse(Cafmal::Event.new(@cafmal_api_url, token).create({name: 'user.logout', message: "#{email} has logged out.", kind: 'login', severity: 'info', team_id: team_id}))
70
69
 
71
- if event_id.nil?
72
- false
73
- else
74
- @token = nil
75
- @decoded_token = nil
76
- true
77
- end
70
+ if event_id.nil?
71
+ false
72
+ else
73
+ @token = nil
74
+ @decoded_token = nil
75
+ true
78
76
  end
77
+ end
78
+
79
+ # refresh token
80
+ def refresh
81
+ headers = {"Content-Type" => "application/json", "Authorization" => "Bearer #{@token}"}
82
+ credentials = {token: @token}.to_json
83
+ refresh_request = Cafmal::Request::Post.new(@cafmal_api_url + '/user_token_refresh', credentials, headers)
84
+ if refresh_request.code < 300
85
+ @token = JSON.parse(refresh_request.response.body)['jwt']
86
+ @decoded_token = {}
87
+ @decoded_token['header'] = JSON.parse(Base64.decode64(@token.split('.')[0]))
88
+ @decoded_token['payload'] = JSON.parse(Base64.decode64(@token.split('.')[1]))
79
89
 
90
+ if (@decoded_token['payload']['role'] != 'worker' && @decoded_token['payload']['role'] != 'alerter')
91
+ team_id = JSON.parse(Cafmal::User.new(@cafmal_api_url, @token).show(@decoded_token['payload']['sub']))["team_id"]
92
+ event = Cafmal::Event.new(@cafmal_api_url, @token)
93
+ event.create({name: 'user.refresh_login', message: "#{@decoded_token['payload']['email']} has refreshed his login.", kind: 'login', severity: 'info', team_id: team_id})
94
+
95
+ #@TODO silence all alerts for your team_id, set silenced_at now + 1h
96
+ end
97
+ return true
98
+ else
99
+ return false
100
+ end
80
101
  end
81
102
  end
82
103
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Cafmal
4
- VERSION = "0.22.0"
4
+ VERSION = "0.23.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cafmal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.22.0
4
+ version: 0.23.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nils Bartels
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-27 00:00:00.000000000 Z
11
+ date: 2016-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler