infinum_id 1.3.1 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +18 -10
- data/app/blueprints/infinum_id/resource_blueprint.rb +10 -0
- data/app/controllers/infinum_id/api/base_controller.rb +10 -0
- data/app/controllers/infinum_id/api/webhooks_controller.rb +41 -0
- data/app/controllers/infinum_id/application_controller.rb +6 -0
- data/app/controllers/infinum_id/{users → resources}/omniauth_callbacks_controller.rb +5 -5
- data/app/controllers/infinum_id/resources_controller.rb +9 -0
- data/app/mailers/infinum_id/application_mailer.rb +6 -0
- data/app/mailers/infinum_id/mailer.rb +24 -0
- data/app/services/infinum_id/after_resource_create.rb +5 -0
- data/app/services/infinum_id/after_resource_update.rb +5 -0
- data/app/services/infinum_id/requests/invite_sender.rb +21 -21
- data/app/services/infinum_id/resources/finder.rb +9 -0
- data/app/services/infinum_id/resources/invite.rb +29 -0
- data/app/services/infinum_id/resources/updater.rb +31 -0
- data/app/views/{user_mailer → infinum_id/mailer}/invite_email.html.erb +1 -1
- data/app/views/{user_mailer → infinum_id/mailer}/invite_email.text.erb +1 -1
- data/app/views/{user_mailer → infinum_id/mailer}/welcome_email.html.erb +1 -1
- data/app/views/{user_mailer → infinum_id/mailer}/welcome_email.text.erb +1 -1
- data/app/workers/infinum_id/resources/invite_worker.rb +11 -0
- data/config/routes.rb +10 -8
- data/infinum_id.gemspec +2 -0
- data/lib/infinum_id/version.rb +1 -1
- data/lib/infinum_id.rb +17 -1
- metadata +47 -18
- data/app/controllers/api/base_controller.rb +0 -6
- data/app/controllers/api/webhooks_controller.rb +0 -42
- data/app/controllers/infinum_id/users_controller.rb +0 -9
- data/app/mailers/application_mailer.rb +0 -4
- data/app/mailers/user_mailer.rb +0 -20
- data/app/services/infinum_id/after_user_create.rb +0 -5
- data/app/services/infinum_id/after_user_update.rb +0 -5
- data/app/services/infinum_id/users/finder.rb +0 -9
- data/app/services/infinum_id/users/invite.rb +0 -29
- data/app/services/infinum_id/users/updater.rb +0 -31
- data/app/workers/infinum_id/users/invite_worker.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0c689ffa0ee0853c5bb5a4c219a70293eecf3f3deded000f38c79b1f72377c7
|
4
|
+
data.tar.gz: 74835c781128e13d41362154f122201a1543e155ae6b8ba2e35a546b6d06330a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 560b23b073b84045aaedd5ad71178d12d411f4d2b44553598e3bb890822a849852c98846e53995ef2efa282f9e6514e8d2143ae9b33137793af5660e072c8131
|
7
|
+
data.tar.gz: f1b58e6f301f68b688a305bfc56103a31b368eddeaf9180ccd7099f5984e3a96beb784ad50fdab75c27d8fd233873abce9aa5907566e0d9d448c7d8eb6df8c10
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
infinum_id (1.
|
4
|
+
infinum_id (1.4.0)
|
5
|
+
blueprinter
|
5
6
|
bundler
|
6
7
|
devise
|
8
|
+
dry-configurable
|
7
9
|
http
|
8
10
|
omniauth-infinum_id
|
9
11
|
redis
|
@@ -58,7 +60,8 @@ GEM
|
|
58
60
|
addressable (2.6.0)
|
59
61
|
public_suffix (>= 2.0.2, < 4.0)
|
60
62
|
arel (9.0.0)
|
61
|
-
bcrypt (3.1.
|
63
|
+
bcrypt (3.1.13)
|
64
|
+
blueprinter (0.19.0)
|
62
65
|
builder (3.2.3)
|
63
66
|
byebug (10.0.2)
|
64
67
|
coderay (1.1.2)
|
@@ -67,7 +70,7 @@ GEM
|
|
67
70
|
crack (0.4.3)
|
68
71
|
safe_yaml (~> 1.0.0)
|
69
72
|
crass (1.0.4)
|
70
|
-
devise (4.6.
|
73
|
+
devise (4.6.2)
|
71
74
|
bcrypt (~> 3.0)
|
72
75
|
orm_adapter (~> 0.1)
|
73
76
|
railties (>= 4.1.0, < 6.0)
|
@@ -77,6 +80,11 @@ GEM
|
|
77
80
|
docile (1.3.1)
|
78
81
|
domain_name (0.5.20190701)
|
79
82
|
unf (>= 0.0.5, < 1.0.0)
|
83
|
+
dry-configurable (0.8.3)
|
84
|
+
concurrent-ruby (~> 1.0)
|
85
|
+
dry-core (~> 0.4, >= 0.4.7)
|
86
|
+
dry-core (0.4.8)
|
87
|
+
concurrent-ruby (~> 1.0)
|
80
88
|
erubi (1.8.0)
|
81
89
|
factory_bot (5.0.0)
|
82
90
|
activesupport (>= 4.2.0)
|
@@ -91,7 +99,7 @@ GEM
|
|
91
99
|
activesupport (>= 4.2.0)
|
92
100
|
hashdiff (0.3.8)
|
93
101
|
hashie (3.6.0)
|
94
|
-
http (4.
|
102
|
+
http (4.1.1)
|
95
103
|
addressable (~> 2.3)
|
96
104
|
http-cookie (~> 1.0)
|
97
105
|
http-form_data (~> 2.0)
|
@@ -131,7 +139,7 @@ GEM
|
|
131
139
|
omniauth (1.9.0)
|
132
140
|
hashie (>= 3.4.6, < 3.7.0)
|
133
141
|
rack (>= 1.6.2, < 3)
|
134
|
-
omniauth-infinum_id (1.
|
142
|
+
omniauth-infinum_id (1.1.0)
|
135
143
|
omniauth-oauth2
|
136
144
|
omniauth-oauth2 (1.6.0)
|
137
145
|
oauth2 (~> 1.1)
|
@@ -176,12 +184,12 @@ GEM
|
|
176
184
|
rake (>= 0.8.7)
|
177
185
|
thor (>= 0.19.0, < 2.0)
|
178
186
|
rake (10.5.0)
|
179
|
-
redis (4.1.
|
187
|
+
redis (4.1.2)
|
180
188
|
redis-namespace (1.6.0)
|
181
189
|
redis (>= 3.0.4)
|
182
|
-
responders (
|
183
|
-
actionpack (>=
|
184
|
-
railties (>=
|
190
|
+
responders (3.0.0)
|
191
|
+
actionpack (>= 5.0)
|
192
|
+
railties (>= 5.0)
|
185
193
|
rspec (3.8.0)
|
186
194
|
rspec-core (~> 3.8.0)
|
187
195
|
rspec-expectations (~> 3.8.0)
|
@@ -204,7 +212,7 @@ GEM
|
|
204
212
|
rspec-support (~> 3.8.0)
|
205
213
|
rspec-support (3.8.0)
|
206
214
|
safe_yaml (1.0.4)
|
207
|
-
sidekiq (5.2.
|
215
|
+
sidekiq (5.2.7)
|
208
216
|
connection_pool (~> 2.2, >= 2.2.2)
|
209
217
|
rack (>= 1.5.0)
|
210
218
|
rack-protection (>= 1.5.0)
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module InfinumId
|
2
|
+
module Api
|
3
|
+
class WebhooksController < Api::BaseController
|
4
|
+
def update_resource_callback
|
5
|
+
return render_not_found unless resource
|
6
|
+
|
7
|
+
resource.update(user_params)
|
8
|
+
InfinumId::AfterResourceUpdate.call(resource, params[:user])
|
9
|
+
|
10
|
+
render json: { resource_name.underscore => 'updated' }
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_resource_callback
|
14
|
+
return render_already_exists if resource
|
15
|
+
|
16
|
+
resource = resource_class.create(user_params.merge(provider: params[:provider]))
|
17
|
+
InfinumId::AfterResourceCreate.call(resource, params[:user])
|
18
|
+
|
19
|
+
render json: { resource_name.underscore => 'created' }
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def user_params
|
25
|
+
params.require(:user).permit(InfinumId.resource_attributes)
|
26
|
+
end
|
27
|
+
|
28
|
+
def resource
|
29
|
+
@resource ||= resource_class.find_by(uid: user_params[:uid])
|
30
|
+
end
|
31
|
+
|
32
|
+
def render_not_found
|
33
|
+
render json: { resource_name.underscore => 'not found' }, status: :not_found
|
34
|
+
end
|
35
|
+
|
36
|
+
def render_already_exists
|
37
|
+
render json: { resource_name.underscore => 'already exists' }, status: :unprocessable_entity
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -2,5 +2,11 @@ module InfinumId
|
|
2
2
|
class ApplicationController < ActionController::Base
|
3
3
|
protect_from_forgery with: :exception
|
4
4
|
respond_to :html
|
5
|
+
|
6
|
+
delegate :resource_name, :resource_class, to: InfinumId
|
7
|
+
|
8
|
+
def current_resource
|
9
|
+
method("current_#{resource_name.underscore}").call
|
10
|
+
end
|
5
11
|
end
|
6
12
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
module InfinumId
|
2
|
-
module
|
2
|
+
module Resources
|
3
3
|
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
4
4
|
def infinum_id
|
5
|
-
|
5
|
+
resource = InfinumId::Resources::Finder.from_omniauth(omniauth)
|
6
6
|
|
7
|
-
if
|
8
|
-
InfinumId::
|
7
|
+
if resource
|
8
|
+
InfinumId::Resources::Updater.call(omniauth['info'], resource)
|
9
9
|
flash[:notice] = I18n.t 'devise.omniauth_callbacks.success', kind: 'InfinumId'
|
10
|
-
sign_in_and_redirect
|
10
|
+
sign_in_and_redirect resource, event: :authentication
|
11
11
|
else
|
12
12
|
flash[:notice] = 'You do not have permission to access this application.'
|
13
13
|
redirect_to root_path
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module InfinumId
|
2
|
+
class Mailer < InfinumId::ApplicationMailer
|
3
|
+
before_action :load_params
|
4
|
+
|
5
|
+
def welcome_email
|
6
|
+
mail(to: @resource.email, subject: "Welcome to #{@service_name}")
|
7
|
+
end
|
8
|
+
|
9
|
+
def invite_email
|
10
|
+
@accept_path = params[:accept_path]
|
11
|
+
|
12
|
+
mail(to: @resource.email, subject: "Invite to #{@service_name}")
|
13
|
+
end
|
14
|
+
|
15
|
+
def load_params
|
16
|
+
@resource = resource_class.find(params[:resource_id])
|
17
|
+
@invited_by = resource_class.find_by(uid: params[:invited_by_uid])
|
18
|
+
@service_name = InfinumId.service_name
|
19
|
+
@service_url = Rails.configuration.host_url
|
20
|
+
end
|
21
|
+
|
22
|
+
delegate :resource_name, :resource_class, to: InfinumId
|
23
|
+
end
|
24
|
+
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
module InfinumId
|
2
2
|
module Requests
|
3
3
|
class InviteSender
|
4
|
-
def initialize(
|
5
|
-
@
|
6
|
-
@
|
4
|
+
def initialize(resource_id, current_resource_uid)
|
5
|
+
@resource = resource_class.find(resource_id)
|
6
|
+
@current_resource_uid = current_resource_uid
|
7
7
|
end
|
8
8
|
|
9
|
-
def self.call(
|
10
|
-
new(
|
9
|
+
def self.call(resource_id, current_resource_uid)
|
10
|
+
new(resource_id, current_resource_uid).call
|
11
11
|
end
|
12
12
|
|
13
13
|
def call
|
@@ -17,7 +17,7 @@ module InfinumId
|
|
17
17
|
|
18
18
|
private
|
19
19
|
|
20
|
-
attr_reader :
|
20
|
+
attr_reader :resource, :current_resource_uid, :response
|
21
21
|
|
22
22
|
def send_invite_request
|
23
23
|
@response = HTTP.headers(headers).post(invitation_url, json: invitation_params)
|
@@ -26,8 +26,8 @@ module InfinumId
|
|
26
26
|
def handle_response
|
27
27
|
case response.code
|
28
28
|
when 200
|
29
|
-
|
30
|
-
send_email if
|
29
|
+
update_resource
|
30
|
+
send_email if InfinumId.infinum_id_send_email
|
31
31
|
when 400, 403, 404
|
32
32
|
return response.to_s
|
33
33
|
when 401..599
|
@@ -35,8 +35,9 @@ module InfinumId
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
def
|
39
|
-
|
38
|
+
def update_resource
|
39
|
+
resource.update(user_params.merge(provider: 'infinum_id'))
|
40
|
+
InfinumId::AfterResourceUpdate.call(resource, params[:user])
|
40
41
|
end
|
41
42
|
|
42
43
|
def send_email
|
@@ -44,15 +45,15 @@ module InfinumId
|
|
44
45
|
end
|
45
46
|
|
46
47
|
def send_invite_email
|
47
|
-
|
48
|
-
|
48
|
+
InfinumId::Mailer.with(
|
49
|
+
resource_id: resource.id, invited_by_uid: current_resource_uid,
|
49
50
|
accept_path: params[:invitation_accept_path]
|
50
51
|
).invite_email.deliver_now
|
51
52
|
end
|
52
53
|
|
53
54
|
def send_welcome_email
|
54
|
-
|
55
|
-
|
55
|
+
InfinumId::Mailer.with(
|
56
|
+
resource_id: resource.id, invited_by_uid: current_resource_uid
|
56
57
|
).welcome_email.deliver_later
|
57
58
|
end
|
58
59
|
|
@@ -61,10 +62,7 @@ module InfinumId
|
|
61
62
|
end
|
62
63
|
|
63
64
|
def user_params
|
64
|
-
params.require(:user).permit(
|
65
|
-
:uid, :email, :first_name, :last_name, :slack_username,
|
66
|
-
:time_zone, :deactivated_at, :avatar_url
|
67
|
-
)
|
65
|
+
params.require(:user).permit(InfinumId.resource_attributes)
|
68
66
|
end
|
69
67
|
|
70
68
|
def headers
|
@@ -76,15 +74,17 @@ module InfinumId
|
|
76
74
|
|
77
75
|
def invitation_params
|
78
76
|
{
|
79
|
-
user:
|
80
|
-
invited_by_uid:
|
81
|
-
send_invitation: !
|
77
|
+
user: InfinumId::ResourceBlueprint.render_as_json(resource),
|
78
|
+
invited_by_uid: current_resource_uid,
|
79
|
+
send_invitation: !InfinumId.infinum_id_send_email
|
82
80
|
}
|
83
81
|
end
|
84
82
|
|
85
83
|
def invitation_url
|
86
84
|
"#{InfinumId.url}/api/invitations"
|
87
85
|
end
|
86
|
+
|
87
|
+
delegate :resource_name, :resource_class, to: InfinumId
|
88
88
|
end
|
89
89
|
end
|
90
90
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module InfinumId
|
2
|
+
module Resources
|
3
|
+
class Invite
|
4
|
+
def initialize(resource_params, current_resource)
|
5
|
+
@resource_params = resource_params
|
6
|
+
@current_resource = current_resource
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.call(resource_params, current_resource)
|
10
|
+
new(resource_params, current_resource).call
|
11
|
+
end
|
12
|
+
|
13
|
+
def call
|
14
|
+
@resource = InfinumId.resource_class.create(@resource_params)
|
15
|
+
|
16
|
+
send_invite_request if @resource.errors.empty?
|
17
|
+
@resource
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
attr_reader :current_resource, :resource
|
23
|
+
|
24
|
+
def send_invite_request
|
25
|
+
InfinumId::Resources::InviteWorker.perform_async(@resource.id, current_resource.uid)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module InfinumId
|
2
|
+
module Resources
|
3
|
+
class Updater
|
4
|
+
def initialize(params, resource)
|
5
|
+
@params = params.deep_symbolize_keys
|
6
|
+
@resource = resource
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.call(params, resource)
|
10
|
+
new(params, resource).call
|
11
|
+
end
|
12
|
+
|
13
|
+
def call
|
14
|
+
update_resource
|
15
|
+
InfinumId::AfterResourceUpdate.call(resource, @params)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
attr_reader :resource_params, :resource
|
21
|
+
|
22
|
+
def update_resource
|
23
|
+
resource.update(resource_params)
|
24
|
+
end
|
25
|
+
|
26
|
+
def resource_params
|
27
|
+
@params.slice(*InfinumId.resource_attributes)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/config/routes.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
|
-
|
3
|
-
omniauth_callbacks: 'infinum_id/users/omniauth_callbacks'
|
4
|
-
}
|
2
|
+
get '/logout', to: 'infinum_id/resources#destroy'
|
5
3
|
|
6
|
-
|
4
|
+
devise_for InfinumId.resource_name.pluralize.underscore, controllers: {
|
5
|
+
omniauth_callbacks: 'infinum_id/resources/omniauth_callbacks'
|
6
|
+
}
|
7
7
|
|
8
|
-
namespace :
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
namespace :infinum_id do
|
9
|
+
namespace :api do
|
10
|
+
scope '/webhooks', :controller => :webhooks do
|
11
|
+
post :update_resource_callback
|
12
|
+
post :create_resource_callback
|
13
|
+
end
|
12
14
|
end
|
13
15
|
end
|
14
16
|
end
|
data/infinum_id.gemspec
CHANGED
data/lib/infinum_id/version.rb
CHANGED
data/lib/infinum_id.rb
CHANGED
@@ -1,10 +1,26 @@
|
|
1
|
-
require 'infinum_id/version'
|
2
1
|
require 'omniauth/infinum_id'
|
2
|
+
require 'infinum_id/version'
|
3
3
|
require 'infinum_id/engine'
|
4
|
+
require 'dry-configurable'
|
5
|
+
require 'blueprinter'
|
4
6
|
require 'devise'
|
5
7
|
require 'sidekiq'
|
8
|
+
require 'http'
|
6
9
|
|
7
10
|
module InfinumId
|
11
|
+
extend Dry::Configurable
|
12
|
+
|
13
|
+
setting :service_name, reader: true
|
14
|
+
setting :resource_name, 'User', reader: true
|
15
|
+
setting :infinum_id_send_email, false, reader: true
|
16
|
+
|
17
|
+
setting :resource_attributes, [:uid, :email, :first_name, :last_name],
|
18
|
+
reader: true
|
19
|
+
|
20
|
+
def self.resource_class
|
21
|
+
resource_name.constantize
|
22
|
+
end
|
23
|
+
|
8
24
|
def self.url
|
9
25
|
dig_secret(:url)
|
10
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: infinum_id
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dajana Jeroncic
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -304,6 +304,34 @@ dependencies:
|
|
304
304
|
- - ">="
|
305
305
|
- !ruby/object:Gem::Version
|
306
306
|
version: '0'
|
307
|
+
- !ruby/object:Gem::Dependency
|
308
|
+
name: dry-configurable
|
309
|
+
requirement: !ruby/object:Gem::Requirement
|
310
|
+
requirements:
|
311
|
+
- - ">="
|
312
|
+
- !ruby/object:Gem::Version
|
313
|
+
version: '0'
|
314
|
+
type: :runtime
|
315
|
+
prerelease: false
|
316
|
+
version_requirements: !ruby/object:Gem::Requirement
|
317
|
+
requirements:
|
318
|
+
- - ">="
|
319
|
+
- !ruby/object:Gem::Version
|
320
|
+
version: '0'
|
321
|
+
- !ruby/object:Gem::Dependency
|
322
|
+
name: blueprinter
|
323
|
+
requirement: !ruby/object:Gem::Requirement
|
324
|
+
requirements:
|
325
|
+
- - ">="
|
326
|
+
- !ruby/object:Gem::Version
|
327
|
+
version: '0'
|
328
|
+
type: :runtime
|
329
|
+
prerelease: false
|
330
|
+
version_requirements: !ruby/object:Gem::Requirement
|
331
|
+
requirements:
|
332
|
+
- - ">="
|
333
|
+
- !ruby/object:Gem::Version
|
334
|
+
version: '0'
|
307
335
|
description: Write a longer description or delete this line.
|
308
336
|
email:
|
309
337
|
- dajana.jeroncic@infinum.hr
|
@@ -321,26 +349,27 @@ files:
|
|
321
349
|
- LICENSE.txt
|
322
350
|
- README.md
|
323
351
|
- Rakefile
|
324
|
-
- app/
|
325
|
-
- app/controllers/api/
|
352
|
+
- app/blueprints/infinum_id/resource_blueprint.rb
|
353
|
+
- app/controllers/infinum_id/api/base_controller.rb
|
354
|
+
- app/controllers/infinum_id/api/webhooks_controller.rb
|
326
355
|
- app/controllers/infinum_id/application_controller.rb
|
327
|
-
- app/controllers/infinum_id/
|
328
|
-
- app/controllers/infinum_id/
|
356
|
+
- app/controllers/infinum_id/resources/omniauth_callbacks_controller.rb
|
357
|
+
- app/controllers/infinum_id/resources_controller.rb
|
329
358
|
- app/helpers/infinum_id/path_helper.rb
|
330
|
-
- app/mailers/application_mailer.rb
|
331
|
-
- app/mailers/
|
359
|
+
- app/mailers/infinum_id/application_mailer.rb
|
360
|
+
- app/mailers/infinum_id/mailer.rb
|
332
361
|
- app/models/infinum_id/application_record.rb
|
333
|
-
- app/services/infinum_id/
|
334
|
-
- app/services/infinum_id/
|
362
|
+
- app/services/infinum_id/after_resource_create.rb
|
363
|
+
- app/services/infinum_id/after_resource_update.rb
|
335
364
|
- app/services/infinum_id/requests/invite_sender.rb
|
336
|
-
- app/services/infinum_id/
|
337
|
-
- app/services/infinum_id/
|
338
|
-
- app/services/infinum_id/
|
339
|
-
- app/views/
|
340
|
-
- app/views/
|
341
|
-
- app/views/
|
342
|
-
- app/views/
|
343
|
-
- app/workers/infinum_id/
|
365
|
+
- app/services/infinum_id/resources/finder.rb
|
366
|
+
- app/services/infinum_id/resources/invite.rb
|
367
|
+
- app/services/infinum_id/resources/updater.rb
|
368
|
+
- app/views/infinum_id/mailer/invite_email.html.erb
|
369
|
+
- app/views/infinum_id/mailer/invite_email.text.erb
|
370
|
+
- app/views/infinum_id/mailer/welcome_email.html.erb
|
371
|
+
- app/views/infinum_id/mailer/welcome_email.text.erb
|
372
|
+
- app/workers/infinum_id/resources/invite_worker.rb
|
344
373
|
- bin/console
|
345
374
|
- bin/setup
|
346
375
|
- config/initializers/devise.rb
|
@@ -1,42 +0,0 @@
|
|
1
|
-
module Api
|
2
|
-
class WebhooksController < Api::BaseController
|
3
|
-
def update_user_callback
|
4
|
-
return render_not_found unless user
|
5
|
-
|
6
|
-
user.update(user_params)
|
7
|
-
InfinumId::AfterUserUpdate.call(user, params[:user])
|
8
|
-
|
9
|
-
render json: { user: 'updated' }
|
10
|
-
end
|
11
|
-
|
12
|
-
def create_user_callback
|
13
|
-
return render_already_exists if user
|
14
|
-
|
15
|
-
user = User.create(user_params.merge(provider: params[:provider]))
|
16
|
-
InfinumId::AfterUserCreate.call(user, params[:user])
|
17
|
-
|
18
|
-
render json: { user: 'created' }
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def user_params
|
24
|
-
params.require(:user).permit(
|
25
|
-
:uid, :email, :first_name, :last_name, :slack_username,
|
26
|
-
:time_zone, :deactivated_at, :avatar_url
|
27
|
-
)
|
28
|
-
end
|
29
|
-
|
30
|
-
def user
|
31
|
-
@user ||= User.find_by(uid: user_params[:uid])
|
32
|
-
end
|
33
|
-
|
34
|
-
def render_not_found
|
35
|
-
render json: { user: 'not found' }, status: :not_found
|
36
|
-
end
|
37
|
-
|
38
|
-
def render_already_exists
|
39
|
-
render json: { user: 'already exists' }, status: :unprocessable_entity
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
data/app/mailers/user_mailer.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
class UserMailer < ApplicationMailer
|
2
|
-
before_action :load_params
|
3
|
-
|
4
|
-
def welcome_email
|
5
|
-
mail(to: @user.email, subject: "Welcome to #{@service_name}")
|
6
|
-
end
|
7
|
-
|
8
|
-
def invite_email
|
9
|
-
@accept_path = params[:accept_path]
|
10
|
-
|
11
|
-
mail(to: @user.email, subject: "Invite to #{@service_name}")
|
12
|
-
end
|
13
|
-
|
14
|
-
def load_params
|
15
|
-
@user = User.find(params[:user_id])
|
16
|
-
@invited_by = User.find_by(uid: params[:invited_by_uid])
|
17
|
-
@service_name = Rails.configuration.name
|
18
|
-
@service_url = Rails.configuration.host_url
|
19
|
-
end
|
20
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module InfinumId
|
2
|
-
module Users
|
3
|
-
class Invite
|
4
|
-
def initialize(user_params, current_user)
|
5
|
-
@user_params = user_params
|
6
|
-
@current_user = current_user
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.call(user_params, current_user)
|
10
|
-
new(user_params, current_user).call
|
11
|
-
end
|
12
|
-
|
13
|
-
def call
|
14
|
-
@user = User.create(@user_params)
|
15
|
-
|
16
|
-
send_invite_request if @user.errors.empty?
|
17
|
-
@user
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
attr_reader :current_user, :user
|
23
|
-
|
24
|
-
def send_invite_request
|
25
|
-
InfinumId::Users::InviteWorker.perform_async(@user.id, current_user.uid)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module InfinumId
|
2
|
-
module Users
|
3
|
-
class Updater
|
4
|
-
def initialize(params, user)
|
5
|
-
@user_params = params.deep_symbolize_keys
|
6
|
-
@user = user
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.call(params, user)
|
10
|
-
new(params, user).call
|
11
|
-
end
|
12
|
-
|
13
|
-
def call
|
14
|
-
update_user
|
15
|
-
InfinumId::AfterUserUpdate.call(user)
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
attr_reader :user_params, :user
|
21
|
-
|
22
|
-
def update_user
|
23
|
-
user.update(user_params)
|
24
|
-
end
|
25
|
-
|
26
|
-
def user_column_names
|
27
|
-
User.column_names
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|