atomic_admin 2.0.0.beta.2 → 2.0.0.beta.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2877b41feec63fee9094438e6f3567435f0be06d1fd38935c572b17e607a8591
4
- data.tar.gz: 83ff3c84cddad21e5f3799934df38ccd3b54d7b0457388bf6d34f8314da788fc
3
+ metadata.gz: e340871aa75000cfd1bac37c983bf94e41f08046844e72e74a69a72c02a84195
4
+ data.tar.gz: 462a55fd27ada27153a5f70239af0e41145bfb3eaeeea5df121b7dc1b8434e91
5
5
  SHA512:
6
- metadata.gz: 0ce24f660fc4df2bce27318395eacd4debae6dc22a190271dd039b611902139ea1a9c6b6dba3d9e4191d1f864379e55d9567e8bd1298324d6567bd837e262975
7
- data.tar.gz: 93c96f5d173f20a59af47ed1740f1f5a0c9bbe5f03b9eed2111f88bf4b1e0cae42224eb554734bfb5942bb6de9e6d67dbb3951b7d00a56041ca56d4b133b1702
6
+ metadata.gz: 31b5a4759d7eac867eaeab01a4a7dfd268f7578f98a99980fe07821964ce1361734d43b353b356a4b6741f0566dff2b012d97a237cdf87e14413f3d8353ab8bc
7
+ data.tar.gz: 06d940995c30afa90ffdb4d59555a89081d0351b0028ee8ca533a3001e5aa31f98202bdd70e52a5a3afe01c1e1d41548b8fc0d6c3eb6f0f467834eeefed83bd5
@@ -0,0 +1,10 @@
1
+ module AtomicAdmin::Api::Admin::V0
2
+ BASE_CONTROLLER = if AtomicAdmin.authenticating_base_controller_class
3
+ AtomicAdmin.authenticating_base_controller_class.constantize
4
+ else
5
+ AtomicAdmin::Api::Admin::V0::AuthenticatingApplicationController
6
+ end
7
+
8
+ class AdminController < BASE_CONTROLLER
9
+ end
10
+ end
@@ -0,0 +1,36 @@
1
+ module AtomicAdmin::Api::Admin::V0
2
+ class AtomicLtiInstallController < AdminController
3
+ def install_params
4
+ params.permit(:iss, :client_id)
5
+ end
6
+
7
+ def find_install
8
+ AtomicLti::Install.find_by(id: params[:id])
9
+ end
10
+
11
+ def index
12
+ render json: AtomicLti::Install.all.order(:id).paginate(page: params[:page], per_page: 30)
13
+ end
14
+
15
+ def create
16
+ AtomicLti::Install.create!(install_params)
17
+ end
18
+
19
+ def show
20
+ install = find_install
21
+ render json: install
22
+ end
23
+
24
+ def update
25
+ install = find_install
26
+ result = install.update!(install_params)
27
+ render json: result
28
+ end
29
+
30
+ def destroy
31
+ install = find_install
32
+ install.destroy
33
+ render json: install
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,43 @@
1
+ module AtomicAdmin::Api::Admin::V0
2
+ class AtomicLtiPlatformController < AdminController
3
+ def platform_params
4
+ params.permit(:iss, :jwks_url, :token_url, :oidc_url)
5
+ end
6
+
7
+ def find_platform
8
+ AtomicLti::Platform.find_by(id: params[:id])
9
+ end
10
+
11
+ def index
12
+ page = AtomicLti::Platform.all.order(:id).paginate(page: params[:page], per_page: 30)
13
+
14
+ render json: {
15
+ platforms: page,
16
+ page: params[:page],
17
+ total_pages: page.total_pages
18
+ }
19
+ end
20
+
21
+ def create
22
+ platform = AtomicLti::Platform.create!(platform_params)
23
+ render json: { platform: platform }
24
+ end
25
+
26
+ def show
27
+ platform = find_platform
28
+ render json: platform
29
+ end
30
+
31
+ def update
32
+ platform = find_platform
33
+ platform.update!(platform_params)
34
+ render json: { platform: find_platform }
35
+ end
36
+
37
+ def destroy
38
+ platform = find_platform
39
+ platform.destroy
40
+ render json: platform
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,59 @@
1
+ module AtomicAdmin::Api::Admin::V0
2
+ class AtomicTenantClientIdStrategyController < AdminController
3
+
4
+ if AtomicAdmin.client_id_strategy_before_action.present?
5
+ before_action AtomicAdmin.client_id_strategy_before_action, only: [:create, :update]
6
+ end
7
+
8
+ def pinned_client_id_params
9
+ params.permit(:iss, :client_id, :application_instance_id)
10
+ end
11
+
12
+ def find_pinned_client_id
13
+ AtomicTenant::PinnedClientId.find_by(id: params[:id])
14
+ end
15
+
16
+ def search
17
+ page = AtomicTenant::PinnedClientId
18
+ .where(application_instance_id: params[:application_instance_id])
19
+ .order(:id).paginate(page: params[:page], per_page: 30)
20
+ render json: {
21
+ pinned_client_ids: page,
22
+ page: params[:page],
23
+ total_pages: page.total_pages
24
+ }
25
+ end
26
+
27
+ # def index
28
+ # page = AtomicTenant::PinnedClientId.all.order(:id).paginate(page: params[:page], per_page: 30)
29
+ # render json: {
30
+ # pinned_client_ids: page,
31
+ # page: params[:page],
32
+ # total_pages: page.total_pages
33
+ # }
34
+ # end
35
+
36
+ def create
37
+ result = AtomicTenant::PinnedClientId.create!(pinned_client_id_params)
38
+ render json: { pinned_client_id: result }
39
+ end
40
+
41
+ def show
42
+ pinned_client_id = find_pinned_client_id
43
+ render json: {pinned_client_id: pinned_client_id}
44
+ end
45
+
46
+ # def update
47
+ # pinned_client_id = find_pinned_client_id
48
+ # pinned_client_id.update!(pinned_client_id_params)
49
+
50
+ # render json: {pinned_client_id: find_pinned_client_id}
51
+ # end
52
+
53
+ def destroy
54
+ pinned_client_id = find_pinned_client_id
55
+ pinned_client_id.destroy
56
+ render json: { pinned_client_id: pinned_client_id }
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,79 @@
1
+ module AtomicAdmin::Api::Admin::V0
2
+ class AtomicTenantDeploymentController < AdminController
3
+ def deployment_params
4
+ params.permit(:iss, :deployment_id, :application_instance_id)
5
+ end
6
+
7
+ def find_deployment
8
+ AtomicTenant::LtiDeployment.find_by(id: params[:id])
9
+ end
10
+
11
+ def search
12
+ tenant_deployments = AtomicTenant::LtiDeployment.
13
+ where(application_instance_id: params[:application_instance_id]).
14
+ joins("LEFT OUTER JOIN public.atomic_lti_deployments"\
15
+ " ON atomic_tenant_lti_deployments.iss = atomic_lti_deployments.iss"\
16
+ " AND atomic_tenant_lti_deployments.deployment_id = atomic_lti_deployments.deployment_id").
17
+ order(:id).
18
+ paginate(page: params[:page], per_page: 30)
19
+
20
+ rows = tenant_deployments.pluck(
21
+ "atomic_tenant_lti_deployments.id",
22
+ "atomic_tenant_lti_deployments.iss",
23
+ "atomic_tenant_lti_deployments.deployment_id",
24
+ "atomic_tenant_lti_deployments.application_instance_id",
25
+ "atomic_lti_deployments.client_id",
26
+ "atomic_lti_deployments.platform_guid",
27
+ )
28
+
29
+ page = rows.map do |row|
30
+ {
31
+ id: row[0],
32
+ iss: row[1],
33
+ deployment_id: row[2],
34
+ application_instance_id: row[3],
35
+ client_id: row[4],
36
+ platform_guid: row[5],
37
+ }
38
+ end
39
+
40
+ render json: {
41
+ deployments: page,
42
+ page: params[:page],
43
+ total_pages: tenant_deployments.total_pages,
44
+ }
45
+ end
46
+
47
+ # def index
48
+ # page = AtomicTenant::LtiDeployment.all.order(:id).paginate(page: params[:page], per_page: 30)
49
+ # render json: {
50
+ # deployments: page,
51
+ # page: params[:page],
52
+ # total_pages: page.total_pages
53
+ # }
54
+ # end
55
+
56
+ def create
57
+ result = AtomicTenant::LtiDeployment.create!(deployment_params)
58
+ render json: { deployment: result }
59
+ end
60
+
61
+ def show
62
+ deployment = find_deployment
63
+ render json: { deployment: deployment }
64
+ end
65
+
66
+ # def update
67
+ # deployment = find_deployment
68
+ # deployment.update!(deployment_params)
69
+
70
+ # render json: {deployment: find_deployment}
71
+ # end
72
+
73
+ def destroy
74
+ deployment = find_deployment
75
+ deployment.destroy
76
+ render json: { deployment: deployment }
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,58 @@
1
+ module AtomicAdmin::Api::Admin::V0
2
+ class AtomicTenantPlatformGuidStrategyController < AdminController
3
+ if AtomicAdmin.platform_guid_strategy_before_action.present?
4
+ before_action AtomicAdmin.platform_guid_strategy_before_action, only: [:create, :update]
5
+ end
6
+
7
+ def pinned_platform_guid_params
8
+ params.permit(:iss, :platform_guid, :application_id, :application_instance_id)
9
+ end
10
+
11
+ def find_pinned_platform_guid
12
+ AtomicTenant::PinnedPlatformGuid.find(params[:id])
13
+ end
14
+
15
+ def search
16
+ page = AtomicTenant::PinnedPlatformGuid
17
+ .where(application_instance_id: params[:application_instance_id])
18
+ .order(:id).paginate(page: params[:page], per_page: 30)
19
+ render json: {
20
+ pinned_platform_guids: page,
21
+ page: params[:page],
22
+ total_pages: page.total_pages
23
+ }
24
+ end
25
+
26
+ # def index
27
+ # page = AtomicTenant::PinnedPlatformGuid.all.order(:id).paginate(page: params[:page], per_page: 30)
28
+ # render json: {
29
+ # pinned_platform_guids: page,
30
+ # page: params[:page],
31
+ # total_pages: page.total_pages
32
+ # }
33
+ # end
34
+
35
+ def create
36
+ result = AtomicTenant::PinnedPlatformGuid.create!(pinned_platform_guid_params)
37
+ render json: { pinned_platform_guid: result }
38
+ end
39
+
40
+ def show
41
+ pinned_platform_guid = find_pinned_platform_guid
42
+ render json: {pinned_platform_guid: pinned_platform_guid}
43
+ end
44
+
45
+ def update
46
+ pinned_platform_guid = find_pinned_platform_guid
47
+ pinned_platform_guid.update!(pinned_platform_guid_params)
48
+
49
+ render json: {pinned_platform_guid: find_pinned_platform_guid}
50
+ end
51
+
52
+ def destroy
53
+ pinned_platform_guid = find_pinned_platform_guid
54
+ pinned_platform_guid.destroy
55
+ render json: { pinned_platform_guid: pinned_platform_guid }
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,6 @@
1
+ module AtomicAdmin::Api::Admin::V0
2
+ class AuthenticatingApplicationController < ActionController::API
3
+ include RequireJwtToken
4
+ before_action :validate_internal_token
5
+ end
6
+ end
@@ -1,14 +1,13 @@
1
1
  module AtomicAdmin::V1
2
2
  class AdminController < ActionController::API
3
3
  include RequireJwtToken
4
- before_action :only_admins!
4
+ before_action :validate_admin_token
5
5
 
6
6
  rescue_from ActiveRecord::RecordNotFound, with: :record_not_found
7
7
  def record_not_found
8
8
  render_error(:not_found)
9
9
  end
10
10
 
11
-
12
11
  protected
13
12
 
14
13
  def json_for(resource)
@@ -36,12 +35,6 @@ module AtomicAdmin::V1
36
35
  render json: error, status: status
37
36
  end
38
37
 
39
- def only_admins!
40
- return if is_atomic_admin?
41
-
42
- user_not_authorized if current_user.blank? && !current_user.admin?
43
- end
44
-
45
38
  def user_not_authorized(message = "Not Authorized")
46
39
  render json: { message: message, }, status: 401
47
40
  end
@@ -22,10 +22,6 @@ module AtomicAdmin::V1
22
22
  }
23
23
  end
24
24
 
25
- def stats
26
- render json: { stats: [] }
27
- end
28
-
29
25
  def show
30
26
  @application_instance = ApplicationInstance.find(params[:id])
31
27
  render json: { application_instance: json_for(@application_instance) }
@@ -1,20 +1,5 @@
1
1
  module RequireJwtToken
2
- extend ActiveSupport::Concern
3
-
4
- included do
5
- attr_accessor :auth_source
6
-
7
- before_action :validate_admin_token
8
- before_action :validate_internal_token
9
- end
10
-
11
- def is_atomic_admin?
12
- self.auth_source == :atomic_admin
13
- end
14
-
15
- def is_internal?
16
- self.auth_source == :internal
17
- end
2
+ extend ActiveSupport::Concern
18
3
 
19
4
  protected
20
5
 
@@ -23,18 +8,14 @@ module RequireJwtToken
23
8
  decoder = AtomicAdmin::JwtToken::JwksDecoder.new(AtomicAdmin.admin_jwks_url)
24
9
  token = decoder.decode(encoded_token)&.first
25
10
  validate_claims!(token)
26
- self.auth_source = :atomic_admin
27
-
28
11
  token
29
- rescue Exception => e
30
- # Capture all exceptions to let the internal token validation handle it
31
- Rails.logger.error "Admin JWT Error occured #{e.inspect}"
32
- nil
12
+
13
+ rescue JWT::DecodeError, AtomicAdmin::JwtToken::InvalidTokenError => e
14
+ Rails.logger.error "JWT Error occured #{e.inspect}"
15
+ render json: { error: "Unauthorized: Invalid token." }, status: :unauthorized
33
16
  end
34
17
 
35
18
  def validate_internal_token
36
- return if is_atomic_admin?
37
-
38
19
  encoded_token = get_encoded_token(request)
39
20
  decoder = AtomicAdmin::JwtToken::SecretDecoder.new(AtomicAdmin.internal_secret)
40
21
  token = decoder.decode!(encoded_token)
@@ -49,7 +30,6 @@ module RequireJwtToken
49
30
  @user = User.find(token["user_id"])
50
31
 
51
32
  sign_in(@user, event: :authentication, store: false)
52
- self.auth_source = :internal
53
33
  rescue JWT::DecodeError, AtomicAdmin::JwtToken::InvalidTokenError => e
54
34
  Rails.logger.error "Internal JWT Error occured #{e.inspect}"
55
35
  render json: { error: "Unauthorized: Invalid token." }, status: :unauthorized
data/config/routes.rb CHANGED
@@ -1,6 +1,21 @@
1
1
  AtomicAdmin::Engine.routes.draw do
2
2
  namespace :api do
3
3
  namespace :admin do
4
+ # NOTE: these are the "legacy" routes that the old admin app relies on. They don't follow the same conventions as the new API.
5
+ # They are also not namespaces under /api/admin/v0 but rather /api/admin/*
6
+ scope module: "v0" do
7
+ resources :atomic_lti_platform
8
+ resources :atomic_lti_install
9
+ resources :atomic_tenant_deployment
10
+ post '/atomic_tenant_deployment/search', to: 'atomic_tenant_deployment#search'
11
+
12
+ resources :atomic_tenant_platform_guid_strategy
13
+ post '/atomic_tenant_platform_guid_strategy/search', to: 'atomic_tenant_platform_guid_strategy#search'
14
+
15
+ resources :atomic_tenant_client_id_strategy
16
+ post '/atomic_tenant_client_id_strategy/search', to: 'atomic_tenant_client_id_strategy#search'
17
+ end
18
+
4
19
  namespace :v1 do
5
20
  resources :lti_platforms
6
21
  resources :lti_installs
@@ -15,12 +30,12 @@ AtomicAdmin::Engine.routes.draw do
15
30
  resources :application_instances do
16
31
  member do
17
32
  get :interactions
18
- get :stats
19
33
  end
20
34
 
21
35
  resources :tenant_client_id_strategies
22
36
  resources :tenant_platform_guid_strategies
23
37
  resources :tenant_deployments
38
+ resources :stats
24
39
  end
25
40
  end
26
41
  end
@@ -10,6 +10,13 @@ module AtomicAdmin::Interaction
10
10
  **kwargs,
11
11
  order: @curr_index,
12
12
  }
13
+
14
+ if @interactions[key][:type] == :analytics && @interactions[key][:controller].present?
15
+ controller_class = @interactions[key][:controller]
16
+ Rails.application.config.to_prepare do
17
+ AtomicAdmin::Api::Admin::V1.const_set(:StatsController, controller_class.constantize)
18
+ end
19
+ end
13
20
  @curr_index += 1
14
21
  end
15
22
 
@@ -1,3 +1,3 @@
1
1
  module AtomicAdmin
2
- VERSION = "2.0.0.beta.2".freeze
2
+ VERSION = "2.0.0.beta.3".freeze
3
3
  end
data/lib/atomic_admin.rb CHANGED
@@ -10,6 +10,9 @@ module AtomicAdmin
10
10
  mattr_accessor :internal_secret
11
11
  mattr_accessor :application_interactions, default: AtomicAdmin::Interaction::Manager.new
12
12
  mattr_accessor :application_instance_interactions, default: AtomicAdmin::Interaction::Manager.new
13
+ mattr_accessor :authenticating_base_controller_class, default: nil
14
+ mattr_accessor :client_id_strategy_before_action, default: nil
15
+ mattr_accessor :platform_guid_strategy_before_action, default: nil
13
16
 
14
17
  def self.configure
15
18
  yield self
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atomic_admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.beta.2
4
+ version: 2.0.0.beta.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Benoit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-05-12 00:00:00.000000000 Z
11
+ date: 2025-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -40,6 +40,13 @@ files:
40
40
  - MIT-LICENSE
41
41
  - README.md
42
42
  - Rakefile
43
+ - app/controllers/atomic_admin/api/admin/v0/admin_controller.rb
44
+ - app/controllers/atomic_admin/api/admin/v0/atomic_lti_install_controller.rb
45
+ - app/controllers/atomic_admin/api/admin/v0/atomic_lti_platform_controller.rb
46
+ - app/controllers/atomic_admin/api/admin/v0/atomic_tenant_client_id_strategy_controller.rb
47
+ - app/controllers/atomic_admin/api/admin/v0/atomic_tenant_deployment_controller.rb
48
+ - app/controllers/atomic_admin/api/admin/v0/atomic_tenant_platform_guid_strategy_controller.rb
49
+ - app/controllers/atomic_admin/api/admin/v0/authenticating_application_controller.rb
43
50
  - app/controllers/atomic_admin/api/admin/v1/application_instances_controller.rb
44
51
  - app/controllers/atomic_admin/api/admin/v1/applications_controller.rb
45
52
  - app/controllers/atomic_admin/api/admin/v1/lti_installs_controller.rb
@@ -48,7 +55,6 @@ files:
48
55
  - app/controllers/atomic_admin/api/admin/v1/tenant_client_id_strategies_controller.rb
49
56
  - app/controllers/atomic_admin/api/admin/v1/tenant_deployments_controller.rb
50
57
  - app/controllers/atomic_admin/api/admin/v1/tenant_platform_guid_strategies_controller.rb
51
- - app/controllers/atomic_admin/authenticating_application_controller.rb
52
58
  - app/controllers/atomic_admin/v1/admin_controller.rb
53
59
  - app/controllers/atomic_admin/v1/application_instances_controller.rb
54
60
  - app/controllers/atomic_admin/v1/applications_controller.rb
@@ -1,18 +0,0 @@
1
- module AtomicAdmin
2
- class AuthenticatingApplicationController < ActionController::API
3
- include AtomicAdmin::JwtToken
4
- # before_action :authenticate_user! # Use validate_token instead for now
5
- before_action :validate_token
6
- before_action :only_admins!
7
-
8
- private
9
-
10
- def only_admins!
11
- user_not_authorized unless current_user.admin?
12
- end
13
-
14
- def user_not_authorized(message = "Not Authorized")
15
- render json: { message: message, }, status: 401
16
- end
17
- end
18
- end