snf_core 0.3.6 → 0.3.8

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.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/snf_core/auth_controller.rb +16 -0
  3. data/app/models/snf_core/quotation.rb +1 -0
  4. data/config/routes.rb +1 -1
  5. data/db/migrate/20250317135148_add_user_to_quotation.rb +5 -0
  6. data/lib/snf_core/version.rb +1 -1
  7. data/spec/dummy/db/schema.rb +4 -1
  8. data/spec/dummy/log/development.log +793 -0
  9. data/spec/dummy/log/test.log +32834 -0
  10. data/spec/dummy/tmp/storage/1x/b3/1xb3eynux1c60fek1qhc2nvp1pqp +0 -0
  11. data/spec/dummy/tmp/storage/3e/c1/3ec10l44sr1t2nptye9ayc3ghqct +0 -0
  12. data/spec/dummy/tmp/storage/4b/jj/4bjj0gif47zey9wtfgchqycn1yvf +0 -0
  13. data/spec/dummy/tmp/storage/4p/en/4peng35m86rx8tqpyj6ekabtkby8 +0 -0
  14. data/spec/dummy/tmp/storage/5m/ym/5mymeg6xe9jzbmzzlgeuc9cpfc7p +0 -0
  15. data/spec/dummy/tmp/storage/74/qy/74qyz5a03ozsho4l4fb1qmcd1iyl +0 -0
  16. data/spec/dummy/tmp/storage/7f/1u/7f1u3qgbmbvx18taa0zeyeau19tv +0 -0
  17. data/spec/dummy/tmp/storage/7t/23/7t23ey0ydqoi3vvknk65qar4vx3g +0 -0
  18. data/spec/dummy/tmp/storage/ap/xq/apxqtkgu8fer3br2c18jxt7vutnh +0 -0
  19. data/spec/dummy/tmp/storage/b9/k7/b9k78cse446bw87afsu7le780d5a +0 -0
  20. data/spec/dummy/tmp/storage/cf/cn/cfcnhpfk26n7siiezv2v1ooo7m2w +0 -0
  21. data/spec/dummy/tmp/storage/cz/gv/czgv4l1kemyizmlq3975u364pppi +0 -0
  22. data/spec/dummy/tmp/storage/e9/gz/e9gzn6o116l2c1f9hdouj5v0vlya +0 -0
  23. data/spec/dummy/tmp/storage/ev/rr/evrrtvk7ccv3ilfm4ucup7l4m72p +0 -0
  24. data/spec/dummy/tmp/storage/f3/33/f333obc6vddqvdsbesykcpxm41y5 +0 -0
  25. data/spec/dummy/tmp/storage/gt/9z/gt9zc94cxlddgqpgomo30vjjihky +0 -0
  26. data/spec/dummy/tmp/storage/if/vw/ifvwj0dh8zlakag28t1y17fa88yd +0 -0
  27. data/spec/dummy/tmp/storage/iq/z5/iqz5993sf7hx44dprnqqpc2b7n52 +0 -0
  28. data/spec/dummy/tmp/storage/iy/3r/iy3rwasm8e6s4z3wmhnwwmo7w9sz +0 -0
  29. data/spec/dummy/tmp/storage/jj/04/jj04m0xpisku4b7q7js1uyve7xdw +0 -0
  30. data/spec/dummy/tmp/storage/jv/ei/jveir920ptm7hq7zysbwk36wfq0x +0 -0
  31. data/spec/dummy/tmp/storage/l3/c1/l3c1ez2fev3a3xkrk7wbp2xdwviv +0 -0
  32. data/spec/dummy/tmp/storage/ny/o3/nyo3lmyjvneit4ame6w4f3ruhnkp +0 -0
  33. data/spec/dummy/tmp/storage/od/wq/odwqixsz0iqwah8tm7eggdxyvsob +0 -0
  34. data/spec/dummy/tmp/storage/pi/6w/pi6wgg4yvzioszy2learhkxyfnyz +0 -0
  35. data/spec/dummy/tmp/storage/pu/t5/put5ap86ooxqmifj7mi0niu507l8 +0 -0
  36. data/spec/dummy/tmp/storage/qd/5o/qd5oes7453z8e5mizm5e2f3zxuiz +0 -0
  37. data/spec/dummy/tmp/storage/sf/i9/sfi9c5zedobbdh9jqt4vzhd9je6b +0 -0
  38. data/spec/dummy/tmp/storage/uo/n6/uon6sfic7g8p3ghvde3zt00r2mid +0 -0
  39. data/spec/dummy/tmp/storage/xw/pd/xwpdbtvmuy3gdokrgrpu3gxv28yp +0 -0
  40. data/spec/examples.txt +203 -198
  41. data/spec/factories/snf_core/quotations.rb +1 -0
  42. data/spec/models/snf_core/quotation_spec.rb +1 -0
  43. data/spec/requests/snf_core/auth_spec.rb +46 -0
  44. metadata +33 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c44ee26535ca2c3687a171ccd8643aca7d5c93b70430801f1f3345b2c2735e34
4
- data.tar.gz: 366988a00ed4ee227d3c1c5d5f08f6077da7f13a2d85a3b2ce9fa7884f1d1729
3
+ metadata.gz: a6089c70b25e81c76d4256e296c173865d35a1719516a5b31f6df20f6da7d603
4
+ data.tar.gz: 6df324619449910eaea298462ed5c5cf85bf54531681c974b73c8ab126508392
5
5
  SHA512:
6
- metadata.gz: 3a8babd301598eb87c0efaa128c8f77dc55c6df08b4ea218f01073ab55fd0210182b3ac10fc15d218bde46f5f344a9df03366673c324909970517c1ba95fe714
7
- data.tar.gz: 581aea9808a0d4499306ecf90d5881e756cf03fe41982406b4e2330f6386bf43f0575a1b8576cd8de09019a6af61afe1d440b187244a8e339dc166b2286f28f4
6
+ metadata.gz: 075272f56cad453bd1267d0ed084adf61eb1e04460ecb09051841c0bbed5cbc58c5908d0113faba2eee7b874c08234ac1d18cff5f5490c4f40c5c510400241af
7
+ data.tar.gz: e6e6c53d4acaa86abd536c056d5ba5909a1332197d690a686fef60b0f857c4c4c9cae00022527bed54372ef4192d2370dd63623e321c70f067c7d3dd51627e61
@@ -73,10 +73,26 @@ module SnfCore
73
73
  user = User.find_by(phone_number: auth_params[:phone_number])
74
74
  return render json: { success: false, error: "User doesn't exist" }, status: :unauthorized unless user
75
75
  return render json: { success: false, error: "Invalid email or password" }, status: :unauthorized unless user.authenticate(auth_params[:password])
76
+ user_role = UserRole.find_by(user: user)
77
+ return render json: { success: false, error: "No role was assigned to your user" }, status: :unauthorized unless user_role
78
+ address = SnfCore::User.find_by(address_id: user.address_id)
79
+ return render json: { success: false, error: "No address was assigned to your user" }, status: :unauthorized unless address
80
+ role = Role.find(user_role.role_id)
81
+ token = @token_service.encode({ user: user.as_json.except("password_digest", "created_at", "updated_at"), role: role.name, address: address.as_json(except: [ :created_at, :updated_at ]) })
82
+ render json: { success: true, token: token, user: user.as_json(except: [ :password_digest ]), role: role.name }
83
+ end
84
+
85
+ def admin_login
86
+ user = User.find_by(phone_number: auth_params[:phone_number])
87
+ return render json: { success: false, error: "User doesn't exist" }, status: :unauthorized unless user
88
+ return render json: { success: false, error: "Invalid email or password" }, status: :unauthorized unless user.authenticate(auth_params[:password])
89
+
76
90
  user_role = UserRole.find_by(user: user)
77
91
  return render json: { success: false, error: "No role was assigned to your user" }, status: :unauthorized unless user_role
78
92
 
79
93
  role = Role.find(user_role.role_id)
94
+ return render json: { success: false, error: "Unauthorized access" }, status: :unauthorized unless role.name == "Admin"
95
+
80
96
  token = @token_service.encode({ user: user.as_json.except("password_digest", "created_at", "updated_at"), role: role.name })
81
97
  render json: { success: true, token: token, user: user.as_json(except: [ :password_digest ]), role: role.name }
82
98
  end
@@ -1,6 +1,7 @@
1
1
  module SnfCore
2
2
  class Quotation < ApplicationRecord
3
3
  belongs_to :item_request
4
+ belongs_to :user
4
5
 
5
6
  validates :price, presence: true, numericality: { greater_than: 0 }
6
7
  validates :valid_until, presence: true
data/config/routes.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  SnfCore::Engine.routes.draw do
2
- mount SnfCore::Engine => "/snf_core"
3
2
  post "auth/login"
3
+ post "auth/admin/login", to: "auth#admin_login"
4
4
  post "auth/signup"
5
5
  post "auth/validate_token"
6
6
  end
@@ -0,0 +1,5 @@
1
+ class AddUserToQuotation < ActiveRecord::Migration[8.0]
2
+ def change
3
+ add_reference :snf_core_quotations, :user, null: false, foreign_key: { to_table: :snf_core_users }
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module SnfCore
2
- VERSION = "0.3.6"
2
+ VERSION = "0.3.8"
3
3
  end
@@ -10,7 +10,7 @@
10
10
  #
11
11
  # It's strongly recommended that you check this file into your version control system.
12
12
 
13
- ActiveRecord::Schema[8.0].define(version: 2025_03_13_103149) do
13
+ ActiveRecord::Schema[8.0].define(version: 2025_03_17_135148) do
14
14
  # These are extensions that must be enabled in order to support this database
15
15
  enable_extension "pg_catalog.plpgsql"
16
16
 
@@ -202,7 +202,9 @@ ActiveRecord::Schema[8.0].define(version: 2025_03_13_103149) do
202
202
  t.text "notes"
203
203
  t.datetime "created_at", null: false
204
204
  t.datetime "updated_at", null: false
205
+ t.bigint "user_id", null: false
205
206
  t.index ["item_request_id"], name: "index_snf_core_quotations_on_item_request_id"
207
+ t.index ["user_id"], name: "index_snf_core_quotations_on_user_id"
206
208
  end
207
209
 
208
210
  create_table "snf_core_roles", force: :cascade do |t|
@@ -333,6 +335,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_03_13_103149) do
333
335
  add_foreign_key "snf_core_orders", "snf_core_users", column: "user_id"
334
336
  add_foreign_key "snf_core_products", "snf_core_categories", column: "category_id"
335
337
  add_foreign_key "snf_core_quotations", "snf_core_item_requests", column: "item_request_id"
338
+ add_foreign_key "snf_core_quotations", "snf_core_users", column: "user_id"
336
339
  add_foreign_key "snf_core_store_inventories", "snf_core_products", column: "product_id"
337
340
  add_foreign_key "snf_core_store_inventories", "snf_core_stores", column: "store_id"
338
341
  add_foreign_key "snf_core_stores", "snf_core_addresses", column: "address_id"