mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
Merge pull request #3383 from techAPJ/patch-4
FIX: handle error for duplicate email_in address
This commit is contained in:
commit
94fea09416
3 changed files with 12 additions and 0 deletions
|
@ -87,6 +87,9 @@ class CategoriesController < ApplicationController
|
|||
if category_params.key? :email_in and category_params[:email_in].length == 0
|
||||
# properly null the value so the database constrain doesn't catch us
|
||||
category_params[:email_in] = nil
|
||||
elsif category_params.key? :email_in and existing_category = Category.find_by(email_in: category_params[:email_in]) and existing_category.id != @category.id
|
||||
# check if email_in address is already in use for other category
|
||||
return render_json_error I18n.t('category.errors.email_in_already_exist', {email_in: category_params[:email_in], category_name: existing_category.name})
|
||||
end
|
||||
|
||||
category_params.delete(:position)
|
||||
|
|
|
@ -341,6 +341,7 @@ en:
|
|||
uncategorized_parent: "Uncategorized can't have a parent category"
|
||||
self_parent: "A subcategory's parent cannot be itself"
|
||||
depth: "You can't nest a subcategory under another"
|
||||
email_in_already_exist: "Incoming email address '%{email_in}' is already in use for '%{category_name}' category."
|
||||
cannot_delete:
|
||||
uncategorized: "Can't delete Uncategorized"
|
||||
has_subcategories: "Can't delete this category because it has sub-categories."
|
||||
|
|
|
@ -174,6 +174,14 @@ describe CategoriesController do
|
|||
end
|
||||
end
|
||||
|
||||
it "returns 422 if email_in address is already in use for other category" do
|
||||
@other_category = Fabricate(:category, name: "Other", email_in: "mail@examle.com" )
|
||||
xhr :put, :update, id: @category.id, name: "Email", email_in: "mail@examle.com", color: "ff0", text_color: "fff"
|
||||
|
||||
expect(response).not_to be_success
|
||||
expect(response.code.to_i).to eq(422)
|
||||
end
|
||||
|
||||
describe "success" do
|
||||
|
||||
it "updates the group correctly" do
|
||||
|
|
Loading…
Reference in a new issue