2012-04-10 14:06:46 +00:00
|
|
|
class TicketsController < ApplicationController
|
2012-04-16 12:47:07 +00:00
|
|
|
skip_before_filter :verify_authenticity_token
|
2012-04-10 14:06:46 +00:00
|
|
|
before_filter :authentication_check
|
|
|
|
|
|
|
|
# GET /tickets
|
|
|
|
def index
|
|
|
|
@tickets = Ticket.all
|
|
|
|
|
2012-04-12 11:27:01 +00:00
|
|
|
render :json => @tickets
|
2012-04-10 14:06:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# GET /tickets/1
|
|
|
|
def show
|
|
|
|
@ticket = Ticket.find(params[:id])
|
|
|
|
|
2012-04-12 11:27:01 +00:00
|
|
|
render :json => @ticket
|
2012-04-10 14:06:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# POST /tickets
|
|
|
|
def create
|
|
|
|
@ticket = Ticket.new(params[:ticket])
|
|
|
|
@ticket.created_by_id = current_user.id
|
|
|
|
|
2012-04-16 11:58:15 +00:00
|
|
|
# check if article is given
|
|
|
|
if !params[:article]
|
|
|
|
render :json => 'article hash is missing', :status => :unprocessable_entity
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
# create ticket
|
|
|
|
if !@ticket.save
|
2012-04-12 11:27:01 +00:00
|
|
|
render :json => @ticket.errors, :status => :unprocessable_entity
|
2012-04-16 11:58:15 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
# create article if given
|
|
|
|
if params[:article]
|
|
|
|
@article = Ticket::Article.new(params[:article])
|
|
|
|
@article.created_by_id = params[:article][:created_by_id] || current_user.id
|
|
|
|
@article.ticket_id = @ticket.id
|
|
|
|
|
|
|
|
# find attachments in upload cache
|
|
|
|
@article['attachments'] = Store.list(
|
|
|
|
:object => 'UploadCache::TicketZoom::' + current_user.id.to_s,
|
|
|
|
:o_id => @article.ticket_id
|
|
|
|
)
|
|
|
|
if !@article.save
|
|
|
|
render :json => @article.errors, :status => :unprocessable_entity
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
# remove attachments from upload cache
|
|
|
|
Store.remove(
|
|
|
|
:object => 'UploadCache::TicketZoom::' + current_user.id.to_s,
|
|
|
|
:o_id => @article.ticket_id
|
|
|
|
)
|
2012-04-10 14:06:46 +00:00
|
|
|
end
|
2012-04-16 11:58:15 +00:00
|
|
|
|
|
|
|
render :json => @ticket, :status => :created
|
2012-04-10 14:06:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# PUT /tickets/1
|
|
|
|
def update
|
|
|
|
@ticket = Ticket.find(params[:id])
|
|
|
|
|
2012-04-12 11:27:01 +00:00
|
|
|
if @ticket.update_attributes(params[:ticket])
|
|
|
|
render :json => @ticket, :status => :ok
|
|
|
|
else
|
|
|
|
render :json => @ticket.errors, :status => :unprocessable_entity
|
2012-04-10 14:06:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# DELETE /tickets/1
|
|
|
|
def destroy
|
|
|
|
@ticket = Ticket.find(params[:id])
|
|
|
|
@ticket.destroy
|
|
|
|
|
2012-04-12 11:27:01 +00:00
|
|
|
head :ok
|
2012-04-10 14:06:46 +00:00
|
|
|
end
|
|
|
|
end
|