Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into 4473-expand-reminder-date-possibilities
  • Loading branch information
jlandiseigsti committed Sep 16, 2024
2 parents bea7a03 + d59c559 commit acba202
Show file tree
Hide file tree
Showing 21 changed files with 176 additions and 47 deletions.
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- I have added tests that prove my fix is effective or that my feature works,
- New and existing unit tests pass locally with my changes ("bundle exec rake"),
- Title include "WIP" if work is in progress.
- I acknowledge that I will *not* force push my branch once reviews have started.
-->

Expand Down
18 changes: 16 additions & 2 deletions app/controllers/admin/account_requests_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class Admin::AccountRequestsController < AdminController
before_action :set_account_request, only: [:reject, :close]

def index
@open_account_requests = AccountRequest.requested.order('created_at DESC')
.page(params[:open_page]).per(15)
Expand All @@ -11,12 +13,24 @@ def for_rejection
end

def reject
account_request = AccountRequest.find(account_request_params[:id])
account_request.reject!(account_request_params[:rejection_reason])
@account_request.reject!(account_request_params[:rejection_reason])
redirect_to admin_account_requests_path, notice: "Account request rejected!"
end

def close
@account_request.close!(account_request_params[:rejection_reason])
redirect_to admin_account_requests_path, notice: "Account request closed!"
rescue => e
redirect_to admin_account_requests_path, alert: e.message
end

def account_request_params
params.require(:account_request).permit(:id, :rejection_reason)
end

private

def set_account_request
@account_request = AccountRequest.find(account_request_params[:id])
end
end
15 changes: 13 additions & 2 deletions app/models/account_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ class AccountRequest < ApplicationRecord

has_one :organization, dependent: :nullify

enum status: %w[started user_confirmed admin_approved rejected].map { |v| [v, v] }.to_h
enum status: %w[started user_confirmed admin_approved rejected admin_closed].map { |v| [v, v] }.to_h

scope :requested, -> { where(status: %w[started user_confirmed]) }
scope :closed, -> { where(status: %w[admin_approved rejected]) }
scope :closed, -> { where(status: %w[admin_approved rejected admin_closed]) }

def self.get_by_identity_token(identity_token)
decrypted_token = JWT.decode(identity_token, Rails.application.secret_key_base, true, { algorithm: 'HS256' })
Expand Down Expand Up @@ -62,6 +62,11 @@ def processed?
organization.present?
end

# @return [Boolean]
def can_be_closed?
started? || user_confirmed?
end

def confirm!
update!(confirmed_at: Time.current, status: 'user_confirmed')
AccountRequestMailer.approval_request(account_request_id: id).deliver_later
Expand All @@ -73,6 +78,12 @@ def reject!(reason)
AccountRequestMailer.rejection(account_request_id: id).deliver_later
end

# @param reason [String]
def close!(reason)
raise 'Cannot be closed from this state' unless can_be_closed?
update!(status: 'admin_closed', rejection_reason: reason)
end

private

def email_not_already_used_by_organization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,10 @@
<td><%= js_button(text: 'Reject',
icon: 'ban',
class: 'reject-button',
data: { request_id: open_account_request.id }) %></td>
data: { request_id: open_account_request.id, modal: 'reject' }) %></td>
<td><%= js_button(text: 'Close (Admin)',
icon: 'times',
class: 'reject-button',
data: { request_id: open_account_request.id, modal: 'close' }) %></td>

</tr>
25 changes: 17 additions & 8 deletions app/views/admin/account_requests/_rejection_modal.html.erb
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
<div class="modal" id="rejection-modal">
<div class="modal" id="reject-modal">
<div class="modal-dialog">

<!-- Modal content-->
<!-- Dynamic modal content-->
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">
Reject Account Request
<h4 class="modal-title" style="text-transform:capitalize">
</h4>
<button type="button" class="close btn-close" data-bs-dismiss="modal">&times;</button>
</div>
<div class="modal-body">
<%= simple_form_for AccountRequest.new, url: reject_admin_account_requests_path, method: :post do |f| %>
<%= simple_form_for AccountRequest.new, url: '', method: :post do |f| %>
<%= f.hidden_field :id, id: :reject_account_request_id %>
<div class="form-inputs">
<%= f.input :rejection_reason, required: true, autofocus: true, wrapper: :input_group %>
<a class="text-danger" style="display:none">Reason must be provided</a>
</div>
<%= submit_button %>
<% end %>
Expand All @@ -23,14 +22,24 @@
</div>

</div>

<!-- set url and title dynamically -->
<script type="module">
$(() => {
$('.reject-button').click((event) => {
event.preventDefault();
let url = `/admin/account_requests/${$(event.target).data('modal')}`

$('#account_request_rejection_reason').val('');
$('#reject_account_request_id').val($(event.target).data('requestId'));
$('#rejection-modal').modal('show');
$('#new_account_request').attr('action', url)
$('.modal-title').text(`${$(event.target).data('modal')} Account Request`)
$('#reject-modal').modal('show');
})
$('button[type="submit"]').click((event) => {
if($('#reject-modal #account_request_rejection_reason').val().trim() === ''){
event.preventDefault();
$('.text-danger').show()
}
})
})
</script>
11 changes: 0 additions & 11 deletions app/views/admin/account_requests/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,3 @@
</div>
</div>
</section>

<script type="module">
$(() => {
$('.reject-button').click((event) => {
event.preventDefault();
$('#account_request_rejection_reason').val('');
$('#reject_account_request_id').val($(event.target).data('requestId'));
$('#rejection-modal').modal('show');
})
})
</script>
1 change: 1 addition & 0 deletions app/views/distributions/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<div class="distribution-title">
<legend class="<%= 'with-request' if distribution.request %>">Items in this distribution</legend>
<% if distribution.request %>
<div class="distribution-request-unit">Quantity - Total Units</div>
<div class="distribution-request-unit">Requested</div>
<% end %>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/views/layouts/partners/navigation/_sidebar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
<li class="nav-item">
<%= link_to(partners_profile_path, class: "nav-link") do %>
<i class="nav-icon fa fa-building"></i>
<p>My Organization</p>
<p>My Profile</p>
<% end %>
</li>

<li class="nav-item">
<%= link_to(edit_partners_profile_path, class: "nav-link") do %>
<i class="nav-icon fa fa-cog"></i>
<p>Edit My Organization</p>
<p>Edit My Profile</p>
<% end %>
</li>

Expand Down
4 changes: 2 additions & 2 deletions app/views/partners/_partner_row.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
<%= invite_button_to(invite_partner_path(partner_row), confirm: "Send an invitation to #{partner_row.name} to begin using the partner application?") %>
<% end %>
<% when "invited" %>
<%= view_button_to partner_path(partner_row) + "#partner-information", { text: "Review Application", icon: "check", type: "warning" } %>
<%= view_button_to partner_path(partner_row) + "#partner-information", { text: "Review Applicant's Profile", icon: "check", type: "warning" } %>
<%= invite_button_to(invite_partner_path(partner_row), confirm: "Re-send an invitation to #{partner_row.name}?", text: 'Re-send Invite') %>
<% when "awaiting_review" %>
<%= view_button_to partner_path(partner_row) + "#partner-information", { text: "Review Application", icon: "check", type: "warning" } %>
<%= view_button_to partner_path(partner_row) + "#partner-information", { text: "Review Applicant's Profile", icon: "check", type: "warning" } %>
<% when "approved" %>
<%= button_to recertify_partner_partner_path(partner_row), data: { confirm: "Recertify partner #{partner_row.name}?"}, class: "btn btn-xs bg-red" do %>
<i class="fa fa-refresh"></i> Request Recertification
Expand Down
2 changes: 1 addition & 1 deletion app/views/partners/profiles/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="row mb-2">
<div class="col-sm-6">
<% content_for :title, "Editing - #{current_partner.name}" %>
<h1><i class="fa fa-edit"></i>&nbsp;&nbsp;Edit My Organization&nbsp;&nbsp;&nbsp;
<h1><i class="fa fa-edit"></i>&nbsp;&nbsp;Edit My Profile&nbsp;&nbsp;&nbsp;
<%= partner_status_badge(current_partner) %>
<small>for <%= current_partner.name %></small>
</h1>
Expand Down
2 changes: 1 addition & 1 deletion app/views/partners/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
<section class="card card-info card-outline" id='partner-information'>
<div class="card-header">
<div class="clearfix">
<h2 class="card-title">Application & Information</h2>
<h2 class="card-title">Partner Profile</h2>
</div>
<div class='pull-right'>
<% unless @partner.approved? %>
Expand Down
23 changes: 17 additions & 6 deletions app/views/purchases/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,28 @@
<div class="card-body p-0">
<table class="table">
<thead>
<tr>
<th>Date of Purchase:</th>
<th>Vendor:</th>
<th>Storage Location:</th>
</tr>
</thead>
<tbody>
<tr>
<th>Date of Purchase:</th>
<th>Vendor:</th>
<th>Storage Location:</th>
<td><%= @purchase.issued_at.to_fs(:distribution_date) %> (entered: <%= @purchase.created_at.to_fs(:distribution_date) %>)</td>
<td><%= @purchase.purchased_from_view %></td>
<td><%= @purchase.storage_view %></td>
</tr>
</table>
<table class="table">
<thead>
<tr>
<th>Comment:</th>
</tr>
</thead>
<tbody>
<tr>
<td><%= @purchase.issued_at.to_fs(:distribution_date) %> (entered: <%= @purchase.created_at.to_fs(:distribution_date) %>)</td>
<td><%= @purchase.purchased_from_view %></td>
<td><%= @purchase.storage_view %></td>
<td><%= @purchase.comment || '' %></td>
</tr>
</table>
</div>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def set_up_flipper
resources :barcode_items
resources :account_requests, only: [:index] do
post :reject, on: :collection
post :close, on: :collection
get :for_rejection, on: :collection
end
resources :questions
Expand Down
2 changes: 1 addition & 1 deletion docs/user_guide/bank/essentials_dashboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ This is pretty much what it sounds like - a list of the requests from your partn
![bottom of dashboard page](images/essentials/dashboard/essentials_dashboard_2.png)

#### Partner Approvals
This lists the partner profiles that have been submitted for approval. Partners can not submit requests until they have been approved. To review the application, click on the "Review Application" button beside the partner in the Action colum. For more details on that, see [Approving a partner](pm_approving_a_partner.md)
This lists the partner profiles that have been submitted for approval. Partners can not submit requests until they have been approved. To review the application, click on the "Review Applicant's Profile" button beside the partner in the Action column. For more details on that, see [Approving a partner](pm_approving_a_partner.md)

#### Bank-wide Low Inventory
This lists items whose *bank-wide* inventory has fallen below the recommended or minimum quantity levels you have set on the items. If the item's level in inventory across the bank has fallen below the minimum quantity, it will appear in red.
Expand Down
15 changes: 15 additions & 0 deletions spec/controllers/admin/account_requests_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
RSpec.describe Admin::AccountRequestsController, type: :controller do
before do
sign_in(create(:super_admin, organization: nil))
end

let(:account_request) { create(:account_request, status: :admin_approved) }

describe "POST #close" do
it "should not close the account request if it is invalid" do
post :close, params: {account_request: {id: account_request.id}}
expect(flash[:alert]).to eq("Cannot be closed from this state")
expect(response).to redirect_to(admin_account_requests_path)
end
end
end
18 changes: 18 additions & 0 deletions spec/models/account_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@
end
end

describe '#can_be_closed?' do
it 'returns true when the status can be closed' do
subject.status = %w[started user_confirmed].sample
expect(subject.can_be_closed?).to eq(true)
end

it 'returns false when the status cannot be closed' do
subject.status = 'rejected'
expect(subject.can_be_closed?).to eq(false)
end
end

specify '#confirm!' do
mail_double = instance_double(ActionMailer::MessageDelivery, deliver_later: nil)
allow(AccountRequestMailer).to receive(:approval_request).and_return(mail_double)
Expand Down Expand Up @@ -159,6 +171,12 @@
expect(mail_double).to have_received(:deliver_later)
end

specify "#close!" do
account_request.close!('because I said so')
expect(account_request.reload.rejection_reason).to eq('because I said so')
expect(account_request).to be_admin_closed
end

describe "versioning" do
it { is_expected.to be_versioned }
end
Expand Down
16 changes: 15 additions & 1 deletion spec/requests/purchases_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,21 @@

describe "GET #show" do
let(:item) { create(:item) }
let!(:purchase) { create(:purchase, :with_items, item: item) }
let(:storage_location) { create(:storage_location, organization: organization, name: 'Some Storage') }
let(:vendor) { create(:vendor, organization: organization, business_name: 'Another Business') }
let(:purchase) { create(:purchase, :with_items, comment: 'Fine day for diapers, it is.', created_at: 1.month.ago, issued_at: 1.day.ago, item: item, storage_location: storage_location, vendor: vendor) }

it "shows the purchase info" do
freeze_time do
date_of_purchase = "#{1.day.ago.to_fs(:distribution_date)} (entered: #{1.month.ago.to_fs(:distribution_date)})"

get purchase_path(id: purchase.id)
expect(response.body).to include(date_of_purchase)
expect(response.body).to include('Another Business')
expect(response.body).to include('Some Storage')
expect(response.body).to include('Fine day for diapers, it is.')
end
end

it "shows an enabled edit button" do
get purchase_path(id: purchase.id)
Expand Down
Loading

0 comments on commit acba202

Please sign in to comment.