From e3fa27a01cd591ea202ff805d79c2b6db6505d22 Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Wed, 10 Jun 2015 06:07:37 +1000 Subject: [PATCH] FEATURE: serialize and update category custom_fields - send to client - update from client --- app/assets/javascripts/discourse/models/category.js | 3 ++- app/controllers/categories_controller.rb | 1 + app/serializers/category_serializer.rb | 3 ++- spec/controllers/categories_controller_spec.rb | 5 +++++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/models/category.js b/app/assets/javascripts/discourse/models/category.js index c354f0d48bc..4f8ede69e72 100644 --- a/app/assets/javascripts/discourse/models/category.js +++ b/app/assets/javascripts/discourse/models/category.js @@ -75,7 +75,8 @@ Discourse.Category = Discourse.Model.extend({ parent_category_id: this.get('parent_category_id'), logo_url: this.get('logo_url'), background_url: this.get('background_url'), - allow_badges: this.get('allow_badges') + allow_badges: this.get('allow_badges'), + custom_fields: this.get('custom_fields') }, type: this.get('id') ? 'PUT' : 'POST' }); diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb index 81994721073..c00b67876d1 100644 --- a/app/controllers/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -146,6 +146,7 @@ class CategoriesController < ApplicationController :background_url, :allow_badges, :slug, + :custom_fields => [params[:custom_fields].try(:keys)], :permissions => [*p.try(:keys)]) end end diff --git a/app/serializers/category_serializer.rb b/app/serializers/category_serializer.rb index 8242a57ff7b..1757652094b 100644 --- a/app/serializers/category_serializer.rb +++ b/app/serializers/category_serializer.rb @@ -10,7 +10,8 @@ class CategorySerializer < BasicCategorySerializer :email_in_allow_strangers, :can_delete, :cannot_delete_reason, - :allow_badges + :allow_badges, + :custom_fields def group_permissions @group_permissions ||= begin diff --git a/spec/controllers/categories_controller_spec.rb b/spec/controllers/categories_controller_spec.rb index 3aa0d31e76b..e838b2e9714 100644 --- a/spec/controllers/categories_controller_spec.rb +++ b/spec/controllers/categories_controller_spec.rb @@ -162,8 +162,12 @@ describe CategoriesController do permissions: { "everyone" => readonly, "staff" => create_post + }, + custom_fields: { + "dancing" => "frogs" } + expect(response.status).to eq(200) @category.reload expect(@category.category_groups.map{|g| [g.group_id, g.permission_type]}.sort).to eq([ @@ -173,6 +177,7 @@ describe CategoriesController do expect(@category.slug).to eq("hello-category") expect(@category.color).to eq("ff0") expect(@category.auto_close_hours).to eq(72) + expect(@category.custom_fields).to eq({"dancing" => "frogs"}) end end end