Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comments.Public = false creates comment as public #233

Closed
manderson01 opened this issue Aug 8, 2016 · 1 comment
Closed

Comments.Public = false creates comment as public #233

manderson01 opened this issue Aug 8, 2016 · 1 comment
Labels
Milestone

Comments

@manderson01
Copy link

We’re using : ZendeskApi_v2_Net35 (with VB.Net) - Yes I know, it's a legacy system

Test Case :

Dim updateTicket As Ticket = New Ticket()
updateTicket.Id = ticketID
updateTicket .RequesterId = ticket.RequesterId
---populate a several fields----

Dim newComment As Comment = New Comment()
startComment = String.Format(results.SelectToken("Comment").ToString(), Common.GetFullNameFromUserName(HttpContext.Current.User.Identity.Name).ToString())
newComment = NewTicketComment(startComment, txtDetailComment.Text, False) 'Note the False on public param
updateTicket .Comment = newComment
api.Tickets.UpdateTicket(updateTicket )

Ticket is updated with new comment however it's showing as public and email sent to customer, instead of false.

The code in this part of my applications has been working okay and only stopped after I moved from the ZendeskApi_v2-2.0.0 to the newer 3.5 and other than the authentication, no other updates were needed.

I found the Issue and a possible work-around, however it would still be a bug and not sure what issues if any the workaround will cause.

When debugging the Core.cs I can confirm the c# Ticket.Comment.Public is set to false. I had a look at what the serialized JSON was and cannot see the false property serialized.

?System.Text.Encoding.Default.GetString(data);
"{\"ticket\":{\"requester_id\":358227191,\"custom_fields\":[{\"id\":22142521},{\"id\":22142531},{\"id\":22391566,\"value\":\"task_to_be_completed_pending_ob_order_entry\"},{\"id\":23359766,\"value\":\"\"},{\"id\":24459363,\"value\":\"received_via_orders\"}],\"comment\":{\"body\":\"No macro selected by Michael Anderson\\test1\"},\"id\":568085}}"

I then modified DefaultValueHandling from IgnoreAndPopulate to just Populate in the json_settings (line 51 ) . Compile, copied to project and debugged. I then got public: false

"{\"ticket\":{\"requester_id\":358227191,\"custom_fields\":[{\"id\":22142521},{\"id\":22142531},{\"id\":22391566,\"value\":\"task_to_be_completed_pending_ob_order_entry\"},{\"id\":23359766,\"value\":\"\"},{\"id\":24459363,\"value\":\"received_via_orders\"}],\"comment\":{\"public\":false,\"body\":\"No macro selected by Michael Anderson\\test2\"},\"id\":568085}}"

I couldn't find any unit tests for ticket comment public : false.

So I think the public false is set as default and is being serialized and passed to Zendesk. Not sure where / how to fix that, I can’t find that code in the source?

image

I did see this Models.AccountsAndActivities, but don’t think it has something to do with it?:

        [JsonProperty("comments_public_by_default")]
        public bool CommentsPublicByDefault { get; set; }
@manderson01 manderson01 changed the title Comments.Public = false not does not create comment as private Comments.Public = false creates comment as public Aug 8, 2016
@manderson01
Copy link
Author

manderson01 commented Aug 8, 2016

Okay so now I understand a little bit more about this. To reduce load from client to server they have a feature to tell the client what the default values are for various keys of the JSON object so they do not need to be set. While this works okay for some. But for me (us) this is a major issue with regards to Boolean properties. The reason I could not find any json DefaultValue notations in the code base is because there is none. With DefaultValueHandling booleans are automatically set to ignore all values if it is set to false.

Since the Zendesk models do not have defaults set on the boolean properties then all false's will not be serialized and sent to zendesk server.

Not sure what the solution would be across the board on Default value handling, the lease intrusive is to decorate all boolean properties with a Include which means that if you set it to false it will send false and if you set it to true it will include true. Thoughts?

        [JsonProperty("public")]
        [JsonProperty(DefaultValueHandling = DefaultValueHandling.Include)]
        public bool Public { get; set; }

References
http://www.newtonsoft.com/json/help/html/reducingserializedjsonsize.htm
http://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_DefaultValueHandling.htm
http://stackoverflow.com/questions/23973056/json-net-defaultvaluehandling-exempting-boolean-alone

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants