bscf-core 0.4.98 → 0.5.0

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: e21ece92c538dd2de05e92798fdbcdb484515fb2b4d51579a49a7743cd845908
4
- data.tar.gz: 323646d95a5005ddf6ba62a24b5b3d0184ab70d2e570cb969104be978e1f378a
3
+ metadata.gz: 225894f65a8e151960ff603ac227cc575754eae6ab1c146ee20542091fa129a5
4
+ data.tar.gz: e9f6a8a6f912ef97dcfe6fc718deae1204d26a17a93995abc369604b6fa4aab2
5
5
  SHA512:
6
- metadata.gz: 19e9f2eb4f89d4849965264b20c08cff31570de7f4c67bd595900475a550986a44b8d803f93e3b82b44db1740ed4ad1c66e3c4f61c10b4e8d8dcf78a82264c88
7
- data.tar.gz: 72ab3727d5ef514d63f5f8219e7635ec0c5446c6cc2993bd67e0f03084602c9bee6fdf67fe195f612aa5ca37621936efa43ee1e511d2971ba59e80fa9a676555
6
+ metadata.gz: 3c1d6726242a8153d72662522730397733670e19ace435ac032521bfab747ee559bcdd9ae3a65d8480d80676a22e907b68504b1f2b6a8a1af76107c8da69e2f9
7
+ data.tar.gz: 01ad96461f4a1f3de25e67b6b361079de48411cdb6748ffc9654040fc67db27bdbba1928e572ef1066ee875834ed73e6652154badf7d68a6a413f94624a8376b
@@ -1,16 +1,18 @@
1
1
  module Bscf
2
2
  module Core
3
3
  class ApplicationController < ActionController::API
4
+ include Pundit::Authorization
5
+
6
+ rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
7
+
4
8
  private
5
9
 
6
- def is_authenticated
7
- render json: { error: "Not authenticated" }, status: :unauthorized unless current_user
10
+ def user_not_authorized
11
+ render json: { error: "You are not authorized to perform this action." }, status: :unauthorized
8
12
  end
9
13
 
10
- def is_allowed
11
- user_role = UserRole.find_by(user: current_user)
12
- role = Role.find(user_role.role_id)
13
- render json: { error: "Not authorized" }, status: :ok unless role.name == "User" || role.name == "Admin"
14
+ def is_authenticated
15
+ render json: { error: "Not authenticated" }, status: :unauthorized unless current_user
14
16
  end
15
17
 
16
18
  def current_user
@@ -0,0 +1,22 @@
1
+ class ApplicationPolicy
2
+ attr_reader :user, :record
3
+
4
+ def initialize(user, record)
5
+ @user = user
6
+ @record = record
7
+ end
8
+
9
+ private
10
+
11
+ def admin?
12
+ user.user_roles.any? { |ur| ur.role.name == "Admin" }
13
+ end
14
+
15
+ def driver?
16
+ user.user_roles.any? { |ur| ur.role.name == "Driver" }
17
+ end
18
+
19
+ def user_role?
20
+ user.user_roles.any? { |ur| ur.role.name == "User" }
21
+ end
22
+ end
@@ -0,0 +1,17 @@
1
+ class UserPolicy < ApplicationPolicy
2
+ def index?
3
+ admin?
4
+ end
5
+
6
+ def show?
7
+ admin?
8
+ end
9
+
10
+ def by_role?
11
+ admin?
12
+ end
13
+
14
+ def has_virtual_account?
15
+ true
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ class UserProfilePolicy < ApplicationPolicy
2
+ def show?
3
+ true
4
+ end
5
+
6
+ def update_kyc?
7
+ admin?
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ class UserRolePolicy < ApplicationPolicy
2
+ def assign_driver?
3
+ admin?
4
+ end
5
+ end
@@ -2,6 +2,7 @@ module Bscf
2
2
  module Core
3
3
  class Engine < ::Rails::Engine
4
4
  isolate_namespace Bscf::Core
5
+ config.autoload_paths << File.expand_path("../../app/policies", __dir__)
5
6
  config.generators.api_only = true
6
7
 
7
8
  config.generators do |g|
@@ -1,5 +1,5 @@
1
1
  module Bscf
2
2
  module Core
3
- VERSION = "0.4.98"
3
+ VERSION = "0.5.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bscf-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.98
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Asrat
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
10
+ date: 2025-07-23 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: active_model_serializers
@@ -147,6 +147,20 @@ dependencies:
147
147
  - - ">="
148
148
  - !ruby/object:Gem::Version
149
149
  version: '0'
150
+ - !ruby/object:Gem::Dependency
151
+ name: pundit
152
+ requirement: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ type: :runtime
158
+ prerelease: false
159
+ version_requirements: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
150
164
  - !ruby/object:Gem::Dependency
151
165
  name: database_cleaner-active_record
152
166
  requirement: !ruby/object:Gem::Requirement
@@ -316,6 +330,10 @@ files:
316
330
  - app/models/bscf/core/virtual_account_transaction.rb
317
331
  - app/models/bscf/core/voucher.rb
318
332
  - app/models/bscf/core/wholesaler_product.rb
333
+ - app/policies/application_policy.rb
334
+ - app/policies/user_policy.rb
335
+ - app/policies/user_profile_policy.rb
336
+ - app/policies/user_role_policy.rb
319
337
  - app/services/bscf/core/gebeta_maps_service.rb
320
338
  - app/services/bscf/core/token_service.rb
321
339
  - app/services/bscf/core/transaction_service.rb
@@ -425,7 +443,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
425
443
  - !ruby/object:Gem::Version
426
444
  version: '0'
427
445
  requirements: []
428
- rubygems_version: 3.6.9
446
+ rubygems_version: 3.6.2
429
447
  specification_version: 4
430
448
  summary: An Engine for Supply Chain Financing
431
449
  test_files: []