Ejemplo n.º 1
0
        public void AddComment(HttpListenerContext context)
        {
            try
            {
                var data    = GetRequestPostData(context.Request);
                var session = ValidateSession(data);

                if (!data.AllKeys.Contains("ticketId"))
                {
                    throw new InputException("ticketId");
                }
                int ticketId = Convert.ToInt32(data["ticketId"]);

                var ticket = ticketData.GetTicket(session, ticketId);
                if (ticket == null || !ticket.Permissions.CanComment)
                {
                    ticketData.LogEvent(session, ticketId, TICKET_EVENT.SECURITY_PREVENTED, null);
                    throw new RequestException("Not authorized to comment on ticket");
                }

                if (!data.AllKeys.Contains("comment"))
                {
                    throw new InputException("comment");
                }
                string comment = data["comment"];

                if (!data.AllKeys.Contains("type"))
                {
                    throw new InputException("type");
                }
                COMMENT_TYPE type = (COMMENT_TYPE)Convert.ToInt32(data["type"]);

                if (type == COMMENT_TYPE.INTERNAL && !ticket.Permissions.CanViewInternalComments)
                {
                    ticketData.LogEvent(session, ticketId, TICKET_EVENT.SECURITY_PREVENTED, null);
                    throw new RequestException("Not authorized to comment internally on ticket");
                }

                commentData.AddComment(session, ticketId, ticketData, comment, comment, type, COMMENT_SOURCE.Web);
                //TODO: Send email
                //TODO: If created by SMS AND public, send SMS

                if (data.AllKeys.Contains("subtask_assigned") && data["subtask_assigned"] != "nulL")
                {
                    int subtaskUserId = Convert.ToInt32(data["subtask_assigned"]);
                    //TODO: Create new subtask
                }

                SendTextResponse(context, "1");
            }
            catch (RequestException e)
            {
                SendUnexpectedError(context, e.Reason);
            }
            catch (InputException e)
            {
                SendMissingParameter(context, e.Reason);
            }
        }