From 3e425344ef6b94025eabce1634e84c3be514a5c8 Mon Sep 17 00:00:00 2001
From: Andy Zhao <17884966+Zhao-Andy@users.noreply.github.com>
Date: Thu, 8 Jul 2021 09:23:10 -0400
Subject: [PATCH] [15-min-fix] Add org id to admin listings form (#14162)
* Add organization ID to admin listings form
* Add local: true to form heh...
---
app/controllers/admin/listings_controller.rb | 2 +-
app/views/admin/listings/edit.html.erb | 6 +++++-
spec/requests/admin/listings_spec.rb | 11 ++++++++++-
3 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/app/controllers/admin/listings_controller.rb b/app/controllers/admin/listings_controller.rb
index 6c63d180a..b5cffc7f3 100644
--- a/app/controllers/admin/listings_controller.rb
+++ b/app/controllers/admin/listings_controller.rb
@@ -2,7 +2,7 @@ module Admin
class ListingsController < Admin::ApplicationController
include ListingsToolkit
ALLOWED_PARAMS = %i[
- published body_markdown title category listing_category_id tag_list action
+ published body_markdown title category listing_category_id tag_list action organization_id
].freeze
layout "admin"
diff --git a/app/views/admin/listings/edit.html.erb b/app/views/admin/listings/edit.html.erb
index 8c05a7612..b0694e1c4 100644
--- a/app/views/admin/listings/edit.html.erb
+++ b/app/views/admin/listings/edit.html.erb
@@ -15,7 +15,7 @@
- <%= form_with model: [:admin, @listing], method: :patch do |form| %>
+ <%= form_with model: [:admin, @listing], method: :patch, local: true do |form| %>
<%= form.label :title %>
<%= form.text_field :title, size: 100, maxlength: 128, class: "form-control" %>
@@ -29,6 +29,10 @@
Comma separated, one space, 8 tags max
<%= form.text_field :tag_list, value: @listing.cached_tag_list, size: 100, class: "form-control" %>
+
+ <%= form.label :organization_id, "Organization ID (Optional)" %>
+ <%= form.text_field :organization_id, value: @listing.organization_id, class: "form-control" %>
+
<%= form.label :listing_category_id %>
<%= form.select :listing_category_id, select_options_for_categories %>
diff --git a/spec/requests/admin/listings_spec.rb b/spec/requests/admin/listings_spec.rb
index d7482308f..d7e08ea6e 100644
--- a/spec/requests/admin/listings_spec.rb
+++ b/spec/requests/admin/listings_spec.rb
@@ -1,6 +1,6 @@
require "rails_helper"
-RSpec.describe "/admin/app/listings", type: :request do
+RSpec.describe "/admin/apps/listings", type: :request do
let(:admin) { create(:user, :super_admin) }
let!(:listing) { create(:listing, user_id: admin.id) }
@@ -18,6 +18,15 @@ RSpec.describe "/admin/app/listings", type: :request do
expect(EdgeCache::BustListings).to have_received(:call)
end
+ it "updates the organization ID" do
+ org = create(:organization)
+ put admin_listing_path(id: listing.id), params: {
+ listing: { organization_id: org.id }
+ }
+ sidekiq_perform_enqueued_jobs
+ expect(listing.reload.organization_id).to eq org.id
+ end
+
describe "GET /admin/app/listings" do
let!(:unpublished_listing) { create(:listing, published: false) }