dscf-core 0.3.7 → 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.
- checksums.yaml +4 -4
- data/app/controllers/concerns/dscf/core/authorizable.rb +3 -0
- data/app/controllers/concerns/dscf/core/common.rb +3 -1
- data/app/controllers/dscf/core/documents_controller.rb +42 -0
- data/app/policies/dscf/core/address_policy.rb +25 -0
- data/app/policies/dscf/core/business_policy.rb +1 -1
- data/app/policies/dscf/core/document_policy.rb +25 -0
- data/app/serializers/dscf/core/document_serializer.rb +9 -1
- data/app/services/dscf/core/notification_service.rb +6 -1
- data/config/routes.rb +1 -0
- data/lib/dscf/core/version.rb +1 -1
- metadata +4 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ca2cb2e351f124278aa1855d908cb84dea04a3842e1216b8485f6d8a73878667
|
|
4
|
+
data.tar.gz: 8563fbf9759f19d08c1699cb35d723cd1ee7cec928e7cbcf5d840880a0404491
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dbf4de0d1af84c42cd807be0c0ee32d1727f1f7fe726d28648c71b174d3d16d4a1a825fd04bcb8480b8c07a4f1841947c2b2d3ca98cc9f65ee59a56373b910b5
|
|
7
|
+
data.tar.gz: 775cb2504183bb0579586918e5a11b25e7dfe0d7120bffd02e17fe391e82cdf5dfadd4a2e98f93aff63be4eea6b50a48d5695562ccd508e92dbe075b0fba9c42
|
|
@@ -13,6 +13,9 @@ module Dscf
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def authorize_action!
|
|
16
|
+
# Only perform automatic before_action authorization for standard REST actions
|
|
17
|
+
return skip_authorization unless %w[index show create update destroy].include?(action_name)
|
|
18
|
+
|
|
16
19
|
policy_target = resolve_policy_target
|
|
17
20
|
return skip_authorization unless policy_target
|
|
18
21
|
|
|
@@ -10,10 +10,12 @@ module Dscf
|
|
|
10
10
|
included do
|
|
11
11
|
before_action :set_clazz
|
|
12
12
|
before_action :set_object, only: %i[show update]
|
|
13
|
+
skip_before_action :authorize_action!, raise: false
|
|
14
|
+
before_action :authorize_action!
|
|
13
15
|
end
|
|
14
16
|
|
|
15
17
|
def index
|
|
16
|
-
authorize @clazz.new,
|
|
18
|
+
authorize @clazz.new, "#{action_name}?"
|
|
17
19
|
|
|
18
20
|
data = nil
|
|
19
21
|
options = {}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
module Dscf
|
|
2
|
+
module Core
|
|
3
|
+
class DocumentsController < ApplicationController
|
|
4
|
+
include Common
|
|
5
|
+
|
|
6
|
+
def index
|
|
7
|
+
super do
|
|
8
|
+
business = Business.find(params[:business_id])
|
|
9
|
+
business.documents
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def create
|
|
14
|
+
super do
|
|
15
|
+
business = Business.find(params[:business_id])
|
|
16
|
+
doc = business.documents.new(document_type: :business_license)
|
|
17
|
+
if params[:document] && params[:document][:file].present?
|
|
18
|
+
doc.files.attach(params[:document][:file])
|
|
19
|
+
end
|
|
20
|
+
doc
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def model_params
|
|
27
|
+
params.require(:document).permit(:document_type, :file)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def eager_loaded_associations
|
|
31
|
+
[:files_attachments]
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def set_object
|
|
35
|
+
business = Business.find(params[:business_id])
|
|
36
|
+
@obj = business.documents.find(params[:id])
|
|
37
|
+
rescue ActiveRecord::RecordNotFound
|
|
38
|
+
render_error("Document not found", status: :not_found)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module Dscf
|
|
2
|
+
module Core
|
|
3
|
+
class AddressPolicy < ApplicationPolicy
|
|
4
|
+
def index?
|
|
5
|
+
user.present?
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def show?
|
|
9
|
+
user.present? && (record.user_id == user.id || record.user_id.nil?)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def create?
|
|
13
|
+
user.present?
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def update?
|
|
17
|
+
user.present? && (record.user_id == user.id || record.user_id.nil?)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def destroy?
|
|
21
|
+
user.present? && (record.user_id == user.id || record.user_id.nil?)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module Dscf
|
|
2
|
+
module Core
|
|
3
|
+
class DocumentPolicy < ApplicationPolicy
|
|
4
|
+
def index?
|
|
5
|
+
user.present?
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def show?
|
|
9
|
+
user.present? && (record.documentable.respond_to?(:user_id) ? record.documentable.user_id == user.id : true)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def create?
|
|
13
|
+
user.present?
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def update?
|
|
17
|
+
user.present? && (record.documentable.respond_to?(:user_id) ? record.documentable.user_id == user.id : true)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def destroy?
|
|
21
|
+
user.present? && (record.documentable.respond_to?(:user_id) ? record.documentable.user_id == user.id : true)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module Dscf
|
|
2
2
|
module Core
|
|
3
3
|
class DocumentSerializer < ActiveModel::Serializer
|
|
4
|
-
attributes :id, :document_type, :file_urls, :is_verified, :verified_at, :created_at, :updated_at
|
|
4
|
+
attributes :id, :document_type, :file_urls, :is_verified, :verified_at, :created_at, :updated_at, :name, :url
|
|
5
5
|
|
|
6
6
|
belongs_to :documentable, polymorphic: true
|
|
7
7
|
belongs_to :verified_by, polymorphic: true, optional: true
|
|
@@ -9,6 +9,14 @@ module Dscf
|
|
|
9
9
|
def file_urls
|
|
10
10
|
object.file_urls
|
|
11
11
|
end
|
|
12
|
+
|
|
13
|
+
def name
|
|
14
|
+
object.files.attached? ? object.files.first.filename.to_s : object.document_type.to_s.titleize
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def url
|
|
18
|
+
object.file_urls.first
|
|
19
|
+
end
|
|
12
20
|
end
|
|
13
21
|
end
|
|
14
22
|
end
|
|
@@ -5,9 +5,14 @@ module Dscf
|
|
|
5
5
|
class NotificationService
|
|
6
6
|
class << self
|
|
7
7
|
def deliver(notification)
|
|
8
|
+
phone = notification.recipient&.phone
|
|
9
|
+
raise ArgumentError, "Recipient phone is blank" if phone.blank?
|
|
8
10
|
adapter = resolve_adapter
|
|
9
|
-
adapter.send_sms(
|
|
11
|
+
adapter.send_sms(phone, notification.body)
|
|
10
12
|
notification.update!(status: :delivered, delivered_at: Time.current)
|
|
13
|
+
rescue => e
|
|
14
|
+
Rails.logger.error("Notification delivery failed: #{e.message}")
|
|
15
|
+
notification.update(status: :failed) rescue nil
|
|
11
16
|
end
|
|
12
17
|
|
|
13
18
|
def resolve_adapter
|
data/config/routes.rb
CHANGED
data/lib/dscf/core/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dscf-core
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Asrat
|
|
@@ -442,6 +442,7 @@ files:
|
|
|
442
442
|
- app/controllers/dscf/core/auth_controller.rb
|
|
443
443
|
- app/controllers/dscf/core/business_types_controller.rb
|
|
444
444
|
- app/controllers/dscf/core/businesses_controller.rb
|
|
445
|
+
- app/controllers/dscf/core/documents_controller.rb
|
|
445
446
|
- app/controllers/dscf/core/fayda_verifications_controller.rb
|
|
446
447
|
- app/controllers/dscf/core/files_controller.rb
|
|
447
448
|
- app/controllers/dscf/core/permissions_controller.rb
|
|
@@ -475,9 +476,11 @@ files:
|
|
|
475
476
|
- app/models/dscf/core/user_profile.rb
|
|
476
477
|
- app/models/dscf/core/user_role.rb
|
|
477
478
|
- app/policies/dscf/core/account_management_policy.rb
|
|
479
|
+
- app/policies/dscf/core/address_policy.rb
|
|
478
480
|
- app/policies/dscf/core/application_policy.rb
|
|
479
481
|
- app/policies/dscf/core/business_policy.rb
|
|
480
482
|
- app/policies/dscf/core/business_type_policy.rb
|
|
483
|
+
- app/policies/dscf/core/document_policy.rb
|
|
481
484
|
- app/policies/dscf/core/permission_policy.rb
|
|
482
485
|
- app/policies/dscf/core/role_policy.rb
|
|
483
486
|
- app/serializers/dscf/core/address_serializer.rb
|