Skip to content

Commit e402746

Browse files
committed
WIP - fixed all namespacing in iam
1 parent ffe50fb commit e402746

16 files changed

+197
-167
lines changed
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# frozen_string_literal: true
22

3-
module Ros::Iam
4-
class ApplicationController < ::ApplicationController
3+
module Ros
4+
module Iam
5+
class ApplicationController < ::ApplicationController
6+
end
57
end
68
end

services/iam/app/controllers/iam/confirmations_controller.rb

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,51 @@
11
# frozen_string_literal: true
22

3-
module Ros::Iam
4-
class ConfirmationsController < Devise::ConfirmationsController
5-
include IsTenantScoped
3+
module Ros
4+
module Iam
5+
class ConfirmationsController < Devise::ConfirmationsController
6+
include IsTenantScoped
67

7-
skip_before_action :authenticate_it!, only: %i[create show]
8+
skip_before_action :authenticate_it!, only: %i[create show]
89

9-
respond_to :json
10+
respond_to :json
1011

11-
# POST /resource/confirmation
12-
def create
13-
Apartment::Tenant.switch tenant_schema(reset_params) do
14-
return super unless find_user!
12+
# POST /resource/confirmation
13+
def create
14+
Apartment::Tenant.switch tenant_schema(reset_params) do
15+
return super unless find_user!
1516

16-
@current_user.send_confirmation_instructions
17+
@current_user.send_confirmation_instructions
1718

18-
if successfully_sent?(@current_user)
19-
render status: :ok, json: { message: 'ok' }
20-
else
21-
render status: :bad_request
19+
if successfully_sent?(@current_user)
20+
render status: :ok, json: { message: 'ok' }
21+
else
22+
render status: :bad_request
23+
end
2224
end
2325
end
24-
end
2526

26-
# Devise v4.7.1 expects this to be a GET request and not PUT which is
27-
# definitely not what I expected.
28-
# https://github.com/plataformatec/devise/blob/v4.7.1/app/controllers/devise/confirmations_controller.rb#L21
29-
#
30-
# GET /resource/confirmation
31-
def show
32-
mail_token = begin
33-
Ros::Jwt.new(confirmation_params[:token]).decode
34-
rescue JWT::DecodeError => e
35-
render status: :bad_request, json: { errors: e }
36-
return
37-
end
38-
39-
return unless mail_token
40-
41-
Apartment::Tenant.switch tenant_schema(mail_token) do
42-
res = User.confirm_by_token(mail_token[:token])
43-
if res.confirmed?
44-
render status: :ok, json: { message: 'ok' }
45-
else
46-
render status: :bad_request, json: { errors: res.errors }
27+
# Devise v4.7.1 expects this to be a GET request and not PUT which is
28+
# definitely not what I expected.
29+
# https://github.com/plataformatec/devise/blob/v4.7.1/app/controllers/devise/confirmations_controller.rb#L21
30+
#
31+
# GET /resource/confirmation
32+
def show
33+
mail_token = begin
34+
Ros::Jwt.new(confirmation_params[:token]).decode
35+
rescue JWT::DecodeError => e
36+
render status: :bad_request, json: { errors: e }
37+
return
38+
end
39+
40+
return unless mail_token
41+
42+
Apartment::Tenant.switch tenant_schema(mail_token) do
43+
res = User.confirm_by_token(mail_token[:token])
44+
if res.confirmed?
45+
render status: :ok, json: { message: 'ok' }
46+
else
47+
render status: :bad_request, json: { errors: res.errors }
48+
end
4749
end
4850
end
4951
end

services/iam/app/controllers/iam/passwords_controller.rb

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,56 @@
11
# frozen_string_literal: true
22

3-
module Ros::Iam
4-
class PasswordsController < Devise::PasswordsController
5-
include IsTenantScoped
3+
module Ros
4+
module Iam
5+
class PasswordsController < Devise::PasswordsController
6+
include IsTenantScoped
67

7-
skip_before_action :authenticate_it!, only: %i[create update]
8+
skip_before_action :authenticate_it!, only: %i[create update]
89

9-
respond_to :json
10+
respond_to :json
1011

11-
# POST /resource/password
12-
def create
13-
Apartment::Tenant.switch tenant_schema(password_params) do
14-
return super unless find_user!
12+
# POST /resource/password
13+
def create
14+
Apartment::Tenant.switch tenant_schema(password_params) do
15+
return super unless find_user!
1516

16-
@current_user.send_reset_password_instructions
17+
@current_user.send_reset_password_instructions
1718

18-
if successfully_sent?(@current_user)
19-
render status: :ok, json: { message: 'ok' }
20-
else
21-
render status: :bad_request
19+
if successfully_sent?(@current_user)
20+
render status: :ok, json: { message: 'ok' }
21+
else
22+
render status: :bad_request
23+
end
2224
end
2325
end
24-
end
2526

26-
# PUT /resource/password
27-
def update
28-
mail_token = begin
29-
Ros::Jwt.new(reset_params[:token]).decode
30-
rescue JWT::DecodeError => e
31-
render status: :bad_request, json: { errors: e }
32-
return
33-
end
34-
35-
return unless mail_token
36-
37-
Apartment::Tenant.switch tenant_schema(mail_token) do
38-
decoded_params = {
39-
reset_password_token: mail_token[:token],
40-
password: reset_params[:password],
41-
password_confirmation: reset_params[:password_confirmation]
42-
}
43-
44-
res = User.reset_password_by_token(decoded_params)
45-
46-
if res.persisted?
47-
res.confirm unless res.confirmed?
48-
@current_jwt = Ros::Jwt.new(res.jwt_payload)
49-
render status: :ok, json: { message: 'ok' }
50-
else
51-
render status: :bad_request, json: { errors: res.errors }
27+
# PUT /resource/password
28+
def update
29+
mail_token = begin
30+
Ros::Jwt.new(reset_params[:token]).decode
31+
rescue JWT::DecodeError => e
32+
render status: :bad_request, json: { errors: e }
33+
return
34+
end
35+
36+
return unless mail_token
37+
38+
Apartment::Tenant.switch tenant_schema(mail_token) do
39+
decoded_params = {
40+
reset_password_token: mail_token[:token],
41+
password: reset_params[:password],
42+
password_confirmation: reset_params[:password_confirmation]
43+
}
44+
45+
res = User.reset_password_by_token(decoded_params)
46+
47+
if res.persisted?
48+
res.confirm unless res.confirmed?
49+
@current_jwt = Ros::Jwt.new(res.jwt_payload)
50+
render status: :ok, json: { message: 'ok' }
51+
else
52+
render status: :bad_request, json: { errors: res.errors }
53+
end
5254
end
5355
end
5456
end

services/iam/app/controllers/iam/sessions_controller.rb

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
# frozen_string_literal: true
22

3-
module Ros::Iam
4-
class SessionsController < Devise::SessionsController
5-
include IsTenantScoped
3+
module Ros
4+
module Iam
5+
class SessionsController < Devise::SessionsController
6+
include IsTenantScoped
67

7-
skip_before_action :authenticate_it!, only: :create
8+
skip_before_action :authenticate_it!, only: :create
89

9-
respond_to :json
10+
respond_to :json
1011

11-
# POST /resource/sign_in
12-
def create
13-
Apartment::Tenant.switch tenant_schema(sign_in_params) do
14-
return super unless login_user!
12+
# POST /resource/sign_in
13+
def create
14+
Apartment::Tenant.switch tenant_schema(sign_in_params) do
15+
return super unless login_user!
1516

16-
@current_jwt = Ros::Jwt.new(current_user.jwt_payload)
17-
render json: json_resource(resource_class: user_resource, record: current_user)
17+
@current_jwt = Ros::Jwt.new(current_user.jwt_payload)
18+
render json: json_resource(resource_class: user_resource, record: current_user)
19+
end
1820
end
1921
end
2022
end
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# frozen_string_literal: true
22

3-
module Ros::Iam
4-
class ApplicationRecord < ::ApplicationRecord
5-
self.abstract_class = true
3+
module Ros
4+
module Iam
5+
class ApplicationRecord < ::ApplicationRecord
6+
self.abstract_class = true
7+
end
68
end
79
end
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# frozen_string_literal: true
22

3-
module Ros::Iam
4-
class ApplicationPolicy < ::ApplicationPolicy
3+
module Ros
4+
module Iam
5+
class ApplicationPolicy < ::ApplicationPolicy
6+
end
57
end
68
end

services/iam/app/resources/ros/iam/action_resource.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# frozen_string_literal: true
22

3-
module Ros::Iam
4-
class ActionResource < Ros::Iam::ApplicationResource
5-
# caching
6-
attributes :name, :resource, :action_type
3+
module Ros
4+
module Iam
5+
class ActionResource < Ros::Iam::ApplicationResource
6+
# caching
7+
attributes :name, :resource, :action_type
78

8-
def action_type
9-
@model.type
9+
def action_type
10+
@model.type
11+
end
1012
end
1113
end
1214
end
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# frozen_string_literal: true
22

3-
module Ros::Iam
4-
class ApplicationResource < ::ApplicationResource
5-
abstract
3+
module Ros
4+
module Iam
5+
class ApplicationResource < ::ApplicationResource
6+
abstract
7+
end
68
end
79
end
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
# frozen_string_literal: true
22

3-
module Ros::Iam
4-
class CredentialResource < Ros::Iam::ApplicationResource
5-
attributes :access_key_id, :owner_type, :owner_id, :secret_access_key
3+
module Ros
4+
module Iam
5+
class CredentialResource < Ros::Iam::ApplicationResource
6+
attributes :access_key_id, :owner_type, :owner_id, :secret_access_key
67

7-
filter :access_key_id
8+
filter :access_key_id
89

9-
def self.descriptions
10-
{
11-
access_key_id: 'The access key'
12-
}
10+
def self.descriptions
11+
{
12+
access_key_id: 'The access key'
13+
}
14+
end
1315
end
1416
end
1517
end
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# frozen_string_literal: true
22

3-
module Ros::Iam
4-
class GroupResource < Ros::Iam::ApplicationResource
5-
attributes :name
6-
has_many :users
3+
module Ros
4+
module Iam
5+
class GroupResource < Ros::Iam::ApplicationResource
6+
attributes :name
7+
has_many :users
78

8-
filter :name
9+
filter :name
10+
end
911
end
1012
end

0 commit comments

Comments
 (0)