the first part of reimplementing has been done
now we have app object and singletons are only: log logn plugin and app git-svn-id: svn://ttmath.org/publicrep/winix/trunk@628 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
214
functions/editticket.cpp
Executable file
214
functions/editticket.cpp
Executable file
@@ -0,0 +1,214 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "editticket.h"
|
||||
#include "functions.h"
|
||||
#include "readticket.h"
|
||||
|
||||
|
||||
|
||||
|
||||
namespace Fun
|
||||
{
|
||||
|
||||
EditTicket::EditTicket()
|
||||
{
|
||||
fun.url = "editticket";
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool EditTicket::HasAccess()
|
||||
{
|
||||
// not logged users cannot edit tickets
|
||||
if( !request->session->puser )
|
||||
return false;
|
||||
|
||||
if( request->dir_table.empty() )
|
||||
return false;
|
||||
|
||||
if( request->is_item || !request->is_ticket )
|
||||
return false;
|
||||
|
||||
if( !system->HasWriteAccess(*request->dir_table.back()) )
|
||||
return false;
|
||||
|
||||
if( !system->mounts.pmount || system->mounts.pmount->type != Mount::ticket )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void EditTicket::EditTicketCheckFirstItem()
|
||||
{
|
||||
if( request->status != WINIX_ERR_OK )
|
||||
return;
|
||||
|
||||
|
||||
if( request->ticket.item_id == -1 )
|
||||
{
|
||||
// creating a new item (the item was deleted by a user)
|
||||
|
||||
Item item;
|
||||
item.parent_id = request->dir_table.back()->id;
|
||||
item.subject = request->dir_table.back()->subject;
|
||||
item.type = Item::file;
|
||||
item.privileges = 0644; // !! tymczasowo
|
||||
functions->SetUser(item);
|
||||
system->PrepareUrl(item);
|
||||
|
||||
request->status = db->AddItem(item);
|
||||
|
||||
if( request->status == WINIX_ERR_OK )
|
||||
{
|
||||
log << log2 << "Content: added the first item with content for the ticket, item.id: " << item.id << logend;
|
||||
request->ticket.item_id = item.id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void EditTicket::EditTicketModTicket()
|
||||
{
|
||||
if( request->status != WINIX_ERR_OK )
|
||||
return;
|
||||
|
||||
Ticket ticket;
|
||||
ReadTicket read_ticket;
|
||||
read_ticket.Read(system, request, &ticket);
|
||||
|
||||
request->ticket.type = ticket.type;
|
||||
request->ticket.status = ticket.status;
|
||||
request->ticket.priority = ticket.priority;
|
||||
request->ticket.category = ticket.category;
|
||||
request->ticket.expected = ticket.expected;
|
||||
request->ticket.progress = ticket.progress;
|
||||
|
||||
request->status = db->EditTicketById(request->ticket);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void EditTicket::EditTicketModDir()
|
||||
{
|
||||
if( request->status != WINIX_ERR_OK )
|
||||
return;
|
||||
|
||||
// we don't modify the url
|
||||
|
||||
Item & dir = *request->dir_table.back();
|
||||
bool edit_dir_subject = (dir.subject != request->item.subject);
|
||||
|
||||
if( edit_dir_subject )
|
||||
{
|
||||
dir.subject = request->item.subject;
|
||||
request->status = db->EditItemById(dir, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void EditTicket::EditTicketModFirstItem()
|
||||
{
|
||||
if( request->status != WINIX_ERR_OK )
|
||||
return;
|
||||
|
||||
// modyfing the first item (the one with content)
|
||||
functions->ReadItemContentWithType(request->item);
|
||||
|
||||
Item item;
|
||||
db->GetItemById(request->ticket.item_id, item);
|
||||
item.subject = request->item.subject;
|
||||
item.content = request->item.content;
|
||||
item.content_type = request->item.content_type;
|
||||
// the url doesn't matter
|
||||
|
||||
db->EditItemById(item, false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void EditTicket::PostFunEditTicketLogAndRedirect()
|
||||
{
|
||||
if( request->status == WINIX_ERR_OK )
|
||||
{
|
||||
log << log2 << "Content: edited a ticket" << logend;
|
||||
system->RedirectToLastDir();
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log1 << "Content: problem with editing a ticket, error code: "
|
||||
<< request->status << logend;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool EditTicket::FunCreateTicketCheckAbuse()
|
||||
{
|
||||
if( !system->rebus.CheckRebus() )
|
||||
{
|
||||
request->status = WINIX_ERR_INCORRECT_REBUS;
|
||||
return false;
|
||||
}
|
||||
|
||||
functions->CheckGetPostTimes();
|
||||
|
||||
if( request->session->spam_score > 0 )
|
||||
{
|
||||
request->status = WINIX_ERR_SPAM;
|
||||
log << log1 << "Content: ignoring due to suspected spamming" << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void EditTicket::MakePost()
|
||||
{
|
||||
functions->ReadItem(request->item, Item::dir);
|
||||
// co z uzytkownikiem i grup<75>? chyba nie wczytane? !!! (wczesniej bylo SetUser() w ReadItem() - teraz nie ma)
|
||||
// dodac informacje o modyfikacji !!!
|
||||
|
||||
if( !FunCreateTicketCheckAbuse() )
|
||||
{
|
||||
functions->ReadItemContentWithType(request->item); // for correctly displaying the form
|
||||
return;
|
||||
}
|
||||
|
||||
if( db->GetTicketByDirId(request->dir_table.back()->id, request->ticket) != WINIX_ERR_OK )
|
||||
{
|
||||
request->status = WINIX_ERR_PERMISSION_DENIED;
|
||||
return;
|
||||
}
|
||||
|
||||
EditTicketCheckFirstItem();
|
||||
EditTicketModTicket();
|
||||
EditTicketModDir();
|
||||
EditTicketModFirstItem();
|
||||
PostFunEditTicketLogAndRedirect();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void EditTicket::MakeGet()
|
||||
{
|
||||
db->GetItemById(request->ticket.item_id, request->item);
|
||||
|
||||
// the subject we get from the last directory
|
||||
request->item.subject = request->dir_table.back()->subject;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace
|
Reference in New Issue
Block a user