Skip to content
Merged
2 changes: 1 addition & 1 deletion app/controllers/admin/organizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def destroy

def organization_params
params.require(:organization)
.permit(:name, :short_name, :street, :city, :state, :zipcode, :email, :url, :logo, :intake_location, :default_email_text, :account_request_id, :reminder_day, :deadline_day,
.permit(:name, :street, :city, :state, :zipcode, :email, :url, :logo, :intake_location, :default_email_text, :account_request_id, :reminder_day, :deadline_day,
users_attributes: %i(name email organization_admin), account_request_attributes: %i(ndbn_member_id id))
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def current_organization
elsif current_role.resource.is_a?(Organization)
current_role.resource
else
Organization.find_by(short_name: params[:organization_name])
Organization.find_by(id: params[:organization_id])
end
end
helper_method :current_organization
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/historical_trends/base_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class HistoricalTrends::BaseController < ApplicationController
def cached_series(type)
Rails.cache.fetch("#{current_organization.short_name}-historical-#{type}-data") { HistoricalTrendService.new(current_organization.id, type).series }
Rails.cache.fetch("#{current_organization.id}-historical-#{type}-data") { HistoricalTrendService.new(current_organization.id, type).series }
end
end
2 changes: 1 addition & 1 deletion app/controllers/organizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def organization_params
request_type_formatter(params)

params.require(:organization).permit(
:name, :short_name, :street, :city, :state,
:name, :street, :city, :state,
:zipcode, :email, :url, :logo, :intake_location,
:default_storage_location, :default_email_text, :reminder_email_text,
:invitation_text, :reminder_day, :deadline_day,
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/historical_data_cache_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class HistoricalDataCacheJob < ApplicationJob
def perform(org_id:, type:)
organization = Organization.find_by(id: org_id)

Rails.cache.write("#{organization.short_name}-historical-#{type}-data", HistoricalTrendService.new(organization.id, type).series)
Rails.cache.write("#{organization.id}-historical-#{type}-data", HistoricalTrendService.new(organization.id, type).series)
end

def queue_name = "low_priority"
Expand Down
9 changes: 3 additions & 6 deletions app/models/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ class Organization < ApplicationRecord

include Deadlinable

# TODO: remove once migration "20250504183911_remove_short_name_from_organizations" has run in production
self.ignored_columns += ["short_name"]

validates :name, presence: true
validates :short_name, presence: true, format: /\A[a-z0-9_]+\z/i, uniqueness: true
validates :url, format: { with: URI::DEFAULT_PARSER.make_regexp, message: "it should look like 'http://www.example.com'" }, allow_blank: true
validates :email, format: { with: URI::MailTo::EMAIL_REGEXP }, allow_blank: true
validate :correct_logo_mime_type
Expand Down Expand Up @@ -149,11 +151,6 @@ def assign_attributes_from_account_request(account_request)
self
end

# NOTE: when finding Organizations, use Organization.find_by(short_name: params[:organization_name])
def to_param
short_name
end

def ordered_requests
requests.order(status: :asc, updated_at: :desc)
end
Expand Down
4 changes: 2 additions & 2 deletions app/services/distribution_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ def perform_distribution_service(&block)
set_error(e)
rescue Errors::InsufficientAllotment => e
distribution.line_items.assign_insufficiency_errors(e.insufficient_items)
Rails.logger.error "[!] #{self.class.name} failed because of Insufficient Allotment #{distribution_organization.short_name}: #{distribution.errors.full_messages} [#{e.message}]"
Rails.logger.error "[!] #{self.class.name} failed because of Insufficient Allotment #{distribution_organization.name}: #{distribution.errors.full_messages} [#{e.message}]"
set_error(e)
rescue StandardError => e
Rails.logger.error "[!] #{self.class.name} failed for #{distribution_organization.short_name}: #{distribution.errors.full_messages} [#{e.inspect}]"
Rails.logger.error "[!] #{self.class.name} failed for #{distribution_organization.name}: #{distribution.errors.full_messages} [#{e.inspect}]"
set_error(e)
ensure
return self
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/organizations/_list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<tbody>
<% @organizations.each do |organization| %>
<tr class="<%= organization.short_name %>">
<tr>
<td><%= organization.name %></td>
<td><%= link_to organization.email, "mailto:#{organization.email}" %></td>
<td class="date"><%= organization.created_at.strftime("%F") %></td>
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/organizations/_organization_row.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<tr class="<%= organization_row.short_name %>">
<tr>
<td><%= organization_row.name %></td>
<td><%= link_to organization_row.email, "mailto:#{organization_row.email}" %></td>
<td class="date"><%= organization_row.created_at.strftime("%F") %></td>
Expand Down
8 changes: 0 additions & 8 deletions app/views/admin/organizations/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,6 @@
<span class="input-group-text"><i class="fa fa-user"></i></span>
<%= f.input_field :name, class: "form-control" %>
<% end %>
<%= f.input :short_name, required: true, autofocus: true, wrapper: :input_group do %>
<span class="input-group-text"><i class="fa fa-desktop"></i></span>
<%= f.input_field :short_name, class: "form-control" %>
<% end %>
<div>
APPROACH with EXTREME CAUTION! Editing the short name will break bookmarked links and calendar notices! If a
bank has asked you to do this, explain this to them first.
</div>
<%= f.input :url, as: :url, placeholder: "http://www.example.com", wrapper: :input_group do %>
<span class="input-group-text"><i class="fa fa-link"></i></span>
<%= f.input_field :url, class: "form-control" %>
Expand Down
1 change: 0 additions & 1 deletion app/views/admin/organizations/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
<%= f.hidden_field :account_request_id, value: @organization.account_request_id %>

<%= f.input :name, required: true, autofocus: true %>
<%= f.input :short_name, required: true, autofocus: true %>
<%= f.input :url, as: :url, placeholder: "http://www.example.com" %>
<%= f.input :email %>
<%= f.input :street %>
Expand Down
6 changes: 0 additions & 6 deletions app/views/organizations/_details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@
<h6 class="font-weight-bold">Name</h6>
<p><%= current_organization&.name %></p>
</div>
<div>
<h6 class="font-weight-bold">Short name</h6>
<p>
<%= @organization.short_name || "Not defined" %>
</p>
</div>
<div>
<h6 class="font-weight-bold">NDBN membership ID</h6>
<p>
Expand Down
4 changes: 0 additions & 4 deletions app/views/organizations/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@
<span class="input-group-text"><i class="fa fa-user"></i></span>
<%= f.input_field :name, class: "form-control" %>
<% end %>
<%= f.input :short_name, required: true, autofocus: true, wrapper: :input_group do %>
<span class="input-group-text"><i class="fa fa-desktop"></i></span>
<%= f.input_field :short_name, disabled: true, class: "form-control" %>
<% end %>
<%= f.input :ndbn_member, label: "NDBN membership ID", wrapper: :input_group do %>
<div class="mb-n3"> <%# Removes "margin-bottom: 1rem" added by "form-group" class below %>
<%= f.association :ndbn_member, label_method: :full_name, value_method: :id, label: false %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/partners/_statuses.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
partner_count = status_counts[status] || 0 %>
<li>
<%= fa_icon icon_mapping[status] || '', class: "bg-partner-#{status} " %>
<%= link_to_unless partner_count.zero?, "#{partner_count} #{status.humanize}", partners_path(organization_name:nil, filters: { by_status: status }), class: ("filtering" if status == current_filtered_status) %>
<%= link_to_unless partner_count.zero?, "#{partner_count} #{status.humanize}", partners_path(filters: { by_status: status }), class: ("filtering" if status == current_filtered_status) %>
</li>
<% end %>
<li>
Expand Down
2 changes: 1 addition & 1 deletion app/views/users/_organization_user.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

<% end %>
<% if current_user.is_admin?(current_organization) && user.has_cached_role?(Role::ORG_ADMIN, current_organization) %>
<%= edit_button_to demote_to_user_organization_path(user_id: user.id, organization_name: current_organization.short_name),
<%= edit_button_to demote_to_user_organization_path(user_id: user.id, organization_id: current_organization.id),
{text: 'Demote to User'},
{method: :post, rel: "nofollow", data: {confirm: 'This will demote the admin to user status. Are you sure that you want to submit this?', size: 'xs'}} unless user.id == current_user.id %>
<% end %>
Expand Down
9 changes: 3 additions & 6 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ def random_record_for_org(org, klass)
# Organizations
# ----------------------------------------------------------------------------

pdx_org = Organization.find_or_create_by!(short_name: "diaper_bank") do |organization|
organization.name = "Pawnee Diaper Bank"
pdx_org = Organization.find_or_create_by!(name: "Pawnee Diaper Bank") do |organization|
organization.street = "P.O. Box 22613"
organization.city = "Pawnee"
organization.state = "IN"
Expand All @@ -46,8 +45,7 @@ def random_record_for_org(org, klass)
end
Organization.seed_items(pdx_org)

sf_org = Organization.find_or_create_by!(short_name: "sf_bank") do |organization|
organization.name = "SF Diaper Bank"
sf_org = Organization.find_or_create_by!(name: "SF Diaper Bank") do |organization|
organization.street = "P.O. Box 12345"
organization.city = "San Francisco"
organization.state = "CA"
Expand All @@ -56,8 +54,7 @@ def random_record_for_org(org, klass)
end
Organization.seed_items(sf_org)

sc_org = Organization.find_or_create_by!(short_name: "sc_bank") do |organization|
organization.name = "Second City Essentials Bank"
sc_org = Organization.find_or_create_by!(name: "Second City Essentials Bank") do |organization|
organization.street = Faker::Address.street_address
organization.city = Faker::Address.city
organization.state = Faker::Address.state_abbr
Expand Down
3 changes: 0 additions & 3 deletions docs/user_guide/bank/getting_started_customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ Here's all the fields, with a bit about the implications of each one:
#### Name
The name of your Essentials Bank. This appears in the headings on most screens, and will appear on printouts (such as the distribution printout many banks use as a packing slip), and most reports.

#### Short name
You don't change this -- we assigned it when we set it up -- it's here for reference for support calls if we need it.

#### NDBN membership ID
This should be filled in already from your Account Request,but if it isn't, you can select it from the list. That list is updated on an irregular basis, so if you are an NDBN member, and you aren't on the list, let us know and we'll get a fresh list uploaded.
This is included on the Annual Survey report. That's the only effect.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion lib/test_helpers/pdf_comparison_test_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ def self.get_logo_file
def self.create_organization_storage_items(logo = get_logo_file)
org = Organization.create!(
name: "Essentials Bank 1",
short_name: "db",
street: "1500 Remount Road",
city: "Front Royal",
state: "VA",
Expand Down
12 changes: 0 additions & 12 deletions spec/controllers/distributions_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
context "when distribution causes inventory to remain above minimum quantity for an organization" do
let(:params) do
{
organization_name: organization.id,
distribution: {
partner_id: partner.id,
issued_at: Date.yesterday,
Expand All @@ -45,7 +44,6 @@
context "when distribution causes inventory to fall below minimum quantity for a storage location" do
let(:params) do
{
organization_name: organization.id,
distribution: {
partner_id: partner.id,
storage_location_id: second_storage_location.id,
Expand All @@ -70,7 +68,6 @@
let(:storage_location) { create(:storage_location, :with_items, item: first_item, item_quantity: 20, organization: organization) }
let(:params) do
{
organization_name: organization.id,
distribution: {
partner_id: partner.id,
storage_location_id: storage_location.id,
Expand All @@ -96,7 +93,6 @@
let(:storage_location) { create(:storage_location, organization: organization) }
let(:params) do
{
organization_name: organization.id,
distribution: {
partner_id: partner.id,
storage_location_id: storage_location.id,
Expand Down Expand Up @@ -140,7 +136,6 @@
end
let(:params) do
{
organization_name: organization.id,
distribution: {
partner_id: partner.id,
storage_location_id: storage_location.id,
Expand Down Expand Up @@ -179,7 +174,6 @@
end
let(:params) do
{
organization_name: organization.id,
distribution: {
partner_id: partner.id,
storage_location_id: storage_location.id,
Expand Down Expand Up @@ -207,7 +201,6 @@
let(:storage_location) { create(:storage_location, :with_items, item: item, item_quantity: 2, organization: organization) }
let(:params) do
{
organization_name: organization.id,
distribution: {
partner_id: partner.id,
storage_location_id: storage_location.id,
Expand All @@ -230,7 +223,6 @@
context "when distribution reminder email is enabled" do
let(:params) do
{
organization_name: organization.id,
distribution: {
partner_id: partner.id,
issued_at: Date.tomorrow,
Expand Down Expand Up @@ -288,7 +280,6 @@
let(:distribution) { create(:distribution, storage_location: storage_location) }
let(:params) do
{
organization_name: organization.id,
id: distribution.id,
distribution: {
storage_location_id: distribution.storage_location.id,
Expand Down Expand Up @@ -326,7 +317,6 @@
let(:distribution) { create(:distribution, storage_location: storage_location, organization: organization) }
let(:params) do
{
organization_name: organization.id,
id: distribution.id,
distribution: {
storage_location_id: distribution.storage_location.id,
Expand Down Expand Up @@ -363,7 +353,6 @@
let(:distribution) { create(:distribution, :with_items, item: item1, storage_location: storage_location, organization: organization) }
let(:params) do
{
organization_name: organization.id,
id: distribution.id,
distribution: {
storage_location_id: distribution.storage_location.id,
Expand Down Expand Up @@ -410,7 +399,6 @@
let(:distribution) { create(:distribution, :with_items, item: item1, storage_location: storage_location, organization: organization, reminder_email_enabled: false, partner: partner) }
let(:params) do
{
organization_name: organization.id,
id: distribution.id,
distribution: {
storage_location_id: distribution.storage_location.id,
Expand Down
6 changes: 1 addition & 5 deletions spec/controllers/help_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@
let(:organization) { create(:organization) }
let(:user) { create(:user, organization: organization) }

let(:default_params) do
{ organization_name: organization.to_param }
end

context "While signed in as a normal user >" do
before do
sign_in(user)
end

describe "GET #show" do
subject { get :show, params: default_params }
subject { get :show }
it "returns http success" do
expect(subject).to be_successful
end
Expand Down
1 change: 0 additions & 1 deletion spec/factories/organizations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
end

sequence(:name) { |n| "Essentials Bank #{n}" } # 037000863427
sequence(:short_name) { |n| "db_#{n}" } # 037000863427
sequence(:email) { |n| "email#{n}@example.com" } # 037000863427
sequence(:url) { |n| "https://organization#{n}.org" } # 037000863427
street { "1500 Remount Road" }
Expand Down
2 changes: 1 addition & 1 deletion spec/jobs/historical_data_cache_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

perform_enqueued_jobs { job }

cached_data = Rails.cache.read("#{organization.short_name}-historical-#{type}-data")
cached_data = Rails.cache.read("#{organization.id}-historical-#{type}-data")
expect(cached_data).to eq(expected_data)
end
end
12 changes: 0 additions & 12 deletions spec/models/organization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@
)).to_not be_valid
end

it "validates that short names are unique" do
expect(create(:organization, short_name: "foo_bar")).to be_valid
expect(build(:organization, short_name: "foo_bar")).to_not be_valid
end

it "validates that attachment file size is not higher than 1 MB" do
fixture_path = Rails.root.join('spec', 'fixtures', 'files', 'logo.jpg')
fixture_file = File.open(fixture_path)
Expand Down Expand Up @@ -246,13 +241,6 @@
end
end

describe "#short_name" do
it "can only contain valid characters" do
expect(build(:organization, short_name: "asdf")).to be_valid
expect(build(:organization, short_name: "Not Legal!")).to_not be_valid
end
end

describe "#ordered_requests" do
let!(:new_active_request) { create(:request, comments: "first active") }
let!(:old_active_request) { create(:request, comments: "second active") }
Expand Down
7 changes: 2 additions & 5 deletions spec/requests/admin/organizations_requests_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
RSpec.describe "Admin::Organizations", type: :request do
let(:organization) { create(:organization) }
let(:default_params) do
{ organization_name: organization.id }
end

context "When logged in as a super admin" do
before do
Expand Down Expand Up @@ -110,7 +107,7 @@
describe "PATCH #update" do
let(:organization) { create(:organization, name: "Original Name") }
subject do
patch admin_organization_path(default_params.merge(id: organization.id, organization: { name: updated_name }))
patch admin_organization_path(id: organization.id, organization: { name: updated_name })
end

context "with a valid update" do
Expand All @@ -128,7 +125,7 @@
let(:successful) { 200 }

subject do
patch admin_organization_path(default_params.merge(id: organization.id, organization: { name: updated_name }))
patch admin_organization_path(id: organization.id, organization: { name: updated_name })
end

it "returns http success" do
Expand Down
Loading