approval2 0.1.9 → 0.2.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
  SHA1:
3
- metadata.gz: 5c160ff94c007a93967fa9e3437e0662ee679913
4
- data.tar.gz: d64aeaab593e7498f67002a6eb862115d11d3f4e
3
+ metadata.gz: 75cbc454c1f7868049f8b32a21390afe4cd64005
4
+ data.tar.gz: 945dc93fc1676c4798ea802f994e97dd743dd9b1
5
5
  SHA512:
6
- metadata.gz: 4cf79b315085c0793603a689d19e0a2a45220680827c9472f462d82f61cae03f0e71dc6539045f544f9423dcbe1e8e738f22fd624926cf2f1a30516c973c62ea
7
- data.tar.gz: c7a83ba157b57dc8323e390f3d90077df4dc738254c37cc84c54d7a72e80b8d7030a6229cbe4186e91a9b91292b7796dee47872f359f54833ad0269ff5f188d8
6
+ metadata.gz: ac57187573a60bf8359d84ad1373db93c34ff306a0e2d0605db193190f155d37fcaad536d514f282ab80477e3caaa410059cc0c0be2154a22591c548e03f3749
7
+ data.tar.gz: f9994e72187dc621ba3af01166b32c40cb9702f7a90495932f4b68f21069c2665e0ed2f523bb6c7579e913d9cd0801b4c8f84f89a355f803139272e2db5e8623
@@ -24,4 +24,5 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "rake", "~> 10.0"
25
25
  spec.add_dependency "audited"
26
26
  spec.add_dependency "will_paginate"
27
+ spec.add_dependency "unscoped_associations"
27
28
  end
@@ -3,47 +3,31 @@ module Approval2
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
- before_filter :before_edit, only: :edit
7
- before_filter :before_approve, only: :approve
8
- before_filter :before_index, only: :index
9
-
10
- def reject
11
- modelName = self.class.name.sub("Controller", "").underscore.split('/').last.singularize
12
- modelKlass = modelName.classify.constantize
13
- x = modelKlass.unscoped.find(params[:id])
14
- x.destroy if x.can_destroy?
15
- flash[:alert] = "The unapproved record has been deleted"
16
- redirect_with_params
17
- end
18
-
6
+ before_action :before_edit, only: :edit
7
+ before_action :before_approve, only: :approve
8
+ before_action :before_index, only: :index
19
9
  end
20
10
 
21
11
 
22
12
  private
23
13
 
24
- # apps can provide redirect params via a known session variable
25
- def redirect_with_params
26
- if session[:approval2_redirect_params].present?
27
- redirect_to unapproved_records_path(session[:approval2_redirect_params])
28
- else
29
- redirect_to unapproved_records_path
30
- end
14
+ def modelName
15
+ self.class.name.sub("Controller", "").underscore.split('/').last.singularize
16
+ end
17
+
18
+ def modelKlass
19
+ moduleName = self.class.name.include?("::") ? self.class.name.split("::").first : ""
20
+ "#{moduleName}::#{modelName.classify}".constantize
31
21
  end
32
22
 
33
23
  def before_index
34
- if (params[:approval_status].present? and params[:approval_status] == 'U')
35
- modelName = self.class.name.sub("Controller", "").underscore.split('/').last.singularize
36
- modelKlass = modelName.classify.constantize
37
-
24
+ if (params[:approval_status].present? and params[:approval_status] == 'U')
38
25
  x = modelKlass.unscoped.where("approval_status =?",'U').order("id desc")
39
- instance_variable_set("@#{modelName}s", x.paginate(:per_page => 10, :page => params[:page]))
26
+ instance_variable_set("@#{modelName}s", x)
40
27
  end
41
28
  end
42
29
 
43
30
  def before_edit
44
- modelName = self.class.name.sub("Controller", "").underscore.split('/').last.singularize
45
- modelKlass = modelName.classify.constantize
46
-
47
31
  x = modelKlass.unscoped.find_by_id(params[:id])
48
32
  if x.approval_status == 'A' && x.unapproved_record.nil?
49
33
  params = (x.attributes).merge({:approved_id => x.id,:approved_version => x.lock_version})
@@ -54,24 +38,20 @@ module Approval2
54
38
  end
55
39
 
56
40
  def before_approve
57
- modelName = self.class.name.sub("Controller", "").underscore.split('/').last.singularize
58
- modelKlass = modelName.classify.constantize
59
-
60
41
  x = modelKlass.unscoped.find(params[:id])
61
42
  modelKlass.transaction do
62
43
  approved_record = x.approve
63
44
  if approved_record.save
45
+ instance_variable_set("@#{modelName}", approved_record)
64
46
  flash[:alert] = "#{modelName.humanize.titleize} record was approved successfully"
65
47
  else
66
48
  msg = approved_record.errors.full_messages
67
49
  flash[:alert] = msg
50
+ instance_variable_set("@#{modelName}", x)
68
51
  raise ActiveRecord::Rollback
69
52
  end
70
53
  end
71
54
  end
72
-
73
-
74
-
75
55
  end
76
56
  end
77
57
 
@@ -5,20 +5,20 @@ module Approval2
5
5
  included do
6
6
  audited except: [:approval_status, :last_action]
7
7
 
8
+ default_scope { where(approval_status: 'A') }
9
+
10
+ after_initialize { self.approval_status = 'U' if new_record? }
11
+
8
12
  # refers to the unapproved record in the common unapproved_record model, this is true only for U records
9
13
  has_one :unapproved_record_entry, :as => :approvable, :class_name => '::UnapprovedRecord'
10
14
 
11
15
  # refers to the approved/unapproved record in the model
12
- belongs_to :unapproved_record, :primary_key => 'approved_id', :foreign_key => 'id', :class_name => self.name, :unscoped => true
13
- belongs_to :approved_record, :foreign_key => 'approved_id', :primary_key => 'id', :class_name => self.name, :unscoped => true
16
+ belongs_to :unapproved_record, -> { unscope(where: :approval_status) }, :primary_key => 'approved_id', :foreign_key => 'id', :class_name => self.name
17
+ belongs_to :approved_record, -> { unscope(where: :approval_status) }, :foreign_key => 'approved_id', :primary_key => 'id', :class_name => self.name
14
18
 
15
19
  validates_uniqueness_of :approved_id, :allow_blank => true
16
20
  validate :validate_unapproved_record
17
21
 
18
- def self.default_scope
19
- where approval_status: 'A'
20
- end
21
-
22
22
 
23
23
  after_create :on_create_create_unapproved_record_entry
24
24
  after_destroy :on_destory_remove_unapproved_record_entries
@@ -62,13 +62,6 @@ module Approval2
62
62
  return approved_record
63
63
  end
64
64
  end
65
-
66
- def can_destroy?
67
- # only unaproved records are allowed to be destroyed
68
- self.approval_status == 'U'
69
- end
70
-
71
- alias_method :enable_reject_button?, :can_destroy?
72
65
 
73
66
  def enable_approve_button?
74
67
  self.approval_status == 'U' ? true : false
@@ -1,3 +1,3 @@
1
1
  module Approval2
2
- VERSION = "0.1.9"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,26 +1,15 @@
1
- - reject_url = polymorphic_path(@record, :action => 'reject') rescue nil
2
1
  - can = can? :approve, @record
3
2
  - approve_flag = @record.enable_approve_button?
4
- - reject_flag = @record.enable_reject_button?
5
3
  %a.btn{"data-toggle" => "modal", :href => "#{!(can && approve_flag) ? '#' : '#myModalApprove'}", :role => "button", :class => "btn btn-primary #{(can && approve_flag) ? '' : 'disabled'}"} Approve
6
- - if reject_url.present?
7
- %a.btn{"data-toggle" => "modal", :href => "#{!(can && approve_flag) ? '#' : '#myModalReject'}", :role => "button", :class => "btn btn-primary #{(can && reject_flag) ? '' : 'disabled'}"} Reject
8
4
  .modal.hide.fade{"id" => "myModalApprove", "aria-hidden" => "true", "aria-labelledby" => " myModalLabel", :role => "dialog", :tabindex => "-1"}
9
5
  .modal-header
10
6
  %button.close{"aria-hidden" => "true", "data-dismiss" => "modal", :type => "button"} ×
11
- %h3#myModalLabel Acknowledge Approval
7
+ %h3#myModalLabel Acknowledge
12
8
  #error_message{:style => 'color:red'}
13
9
  .modal-body
14
- = simple_form_for @record, :url => {:action => 'approve'}, :method => :put do |ef|
10
+ = simple_form_for @record, :url => {:action => 'approve'}, :method => :put, :html=>{:id=>"transition"} do |ef|
15
11
  = ef.input :updated_by, :as => :hidden, :input_html => {:value => current_user.id}
16
- = submit_tag "Confirm", :class=>"btn btn-primary transition_button"
17
- .modal.hide.fade{"id" => "myModalReject", "aria-hidden" => "true", "aria-labelledby" => " myModalLabel", :role => "dialog", :tabindex => "-1"}
18
- .modal-header
19
- %button.close{"aria-hidden" => "true", "data-dismiss" => "modal", :type => "button"} ×
20
- %h3#myModalLabel Acknowledge Rejection
21
- #error_message{:style => 'color:red'}
22
- .modal-body
23
- = link_to 'Confirm', reject_url, method: :put, :class=>"btn btn-primary transition_button"
12
+ = submit_tag "Confirm", :class=>"btn btn-primary transition_button", :id => "transition_button"
24
13
  %p{:style => 'color:green;'}
25
14
  = created_or_edited_by(@record)
26
15
  %br
@@ -1,4 +1,4 @@
1
- class CreateUnapprovedRecords < ActiveRecord::Migration
1
+ class CreateUnapprovedRecords < ActiveRecord::Migration[5.1]
2
2
  def change
3
3
  create_table :unapproved_records, {:sequence_start_value => '1 cache 20 order increment by 1'} do |t|
4
4
  t.integer :approvable_id
@@ -11,10 +11,5 @@ class UnapprovedRecordsController < ApplicationController
11
11
  end
12
12
 
13
13
  @records = result.paginate(:per_page => 10, :page => params[:page]) rescue []
14
-
15
- # the approval2 gem requires a known session variable to include any redirect params to be sent to the unapproved_records_path
16
- # for the reject action
17
- session[:approval2_redirect_params] = {param1: 'some_param', param2: 'some_other_param'}
18
-
19
14
  end
20
15
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: approval2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - akil
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-02 00:00:00.000000000 Z
11
+ date: 2018-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: unscoped_associations
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description:
70
84
  email:
71
85
  - akhilesh.kataria@quantiguous.com