Skip to content

A platform for community discussion. Free, open, simple.

DEV: Revert Object Setting upload changes (#36708)

Isaac Janzen27f3bda4c65a
diff --git a/frontend/discourse/admin/components/schema-setting/types/upload.gjs b/frontend/discourse/admin/components/schema-setting/types/upload.gjs
index bc8d0c61585..5cfd81fd7b2 100644
--- a/frontend/discourse/admin/components/schema-setting/types/upload.gjs
+++ b/frontend/discourse/admin/components/schema-setting/types/upload.gjs
@@ -11,7 +11,7 @@ export default class SchemaSettingTypeUpload extends Component {
@action
uploadDone(upload) {
this.uploadUrl = upload.url;
- this.args.onChange(upload.id);
+ this.args.onChange(upload.url);
}
@action
diff --git a/lib/schema_settings_object_validator.rb b/lib/schema_settings_object_validator.rb
index 58ad66d344d..4501c7bda42 100644
--- a/lib/schema_settings_object_validator.rb
+++ b/lib/schema_settings_object_validator.rb
@@ -137,7 +137,18 @@ class SchemaSettingsObjectValidator
when "integer", "topic", "post"
value.is_a?(Integer)
when "upload"
- value.is_a?(Integer)
+ if value.is_a?(String)
+ if upload = Upload.get_from_url(value)
+ @object[property_name] = upload.id
+ # upload already verified via get_from_url, so we can add it to valid ids
+ (@valid_ids_lookup["upload"] ||= Set.new) << upload.id
+ true
+ else
+ false
+ end
+ else
+ value.is_a?(Integer)
+ end
when "float"
value.is_a?(Float) || value.is_a?(Integer)
when "boolean"
diff --git a/spec/lib/schema_settings_object_validator_spec.rb b/spec/lib/schema_settings_object_validator_spec.rb
index afa256ef567..acbd8d62333 100644
--- a/spec/lib/schema_settings_object_validator_spec.rb
+++ b/spec/lib/schema_settings_object_validator_spec.rb
@@ -725,16 +725,6 @@ RSpec.describe SchemaSettingsObjectValidator do
)
end
- it "should validate upload ID successfully" do
- upload = Fabricate(:upload)
- schema = { name: "section", properties: { upload_property: { type: "upload" } } }
-
- validator = described_class.new(schema: schema, object: { upload_property: upload.id })
- errors = validator.validate
-
- expect(errors).to eq({})
- end
-
it "should return the right hash of error messages when value is an invalid URL string" do
schema = { name: "section", properties: { upload_property: { type: "upload" } } }
@@ -799,55 +789,6 @@ RSpec.describe SchemaSettingsObjectValidator do
# only 1 SQL query should be executed to check if upload ids are valid
expect(queries.length).to eq(1)
end
-
- it "should validate multiple upload IDs successfully" do
- upload1 = Fabricate(:upload)
- upload2 = Fabricate(:upload)
- schema = {
- name: "section",
- properties: {
- upload_property_1: {
- type: "upload",
- },
- upload_property_2: {
- type: "upload",
- },
- },
- }
-
- object = { upload_property_1: upload1.id, upload_property_2: upload2.id }
- validator = described_class.new(schema: schema, object: object)
- errors = validator.validate
-
- expect(errors).to eq({})
- end
-
- it "should accept and store upload IDs" do
- upload1 = Fabricate(:upload)
- upload2 = Fabricate(:upload)
- schema = {
- name: "section",
- properties: {
- upload_field_1: {
- type: "upload",
- },
- upload_field_2: {
- type: "upload",
- },
- },
- }
-
- objects = [{ upload_field_1: upload1.id, upload_field_2: upload2.id }]
-
- # Validate
- errors = described_class.validate_objects(schema: schema, objects: objects)
- expect(errors).to eq([])
-
- expect(objects.first[:upload_field_1]).to eq(upload1.id)
- expect(objects.first[:upload_field_2]).to eq(upload2.id)
- expect(objects.first[:upload_field_1]).to be_a(Integer)
- expect(objects.first[:upload_field_2]).to be_a(Integer)
- end
end
context "for tag properties" do