From 0e5097777967f77754214e17a1265922c932f490 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Sat, 6 Feb 2010 14:08:44 +0000 Subject: [PATCH] added: 'rm' function can work with tickets git-svn-id: svn://ttmath.org/publicrep/winix/trunk@565 e52654a7-88a9-db11-a3e9-0013d4bc506e --- content/content.h | 2 ++ content/editticket.cpp | 28 +++++++++++++++++ content/rm.cpp | 53 +++++++++++++++++++------------- core/db.cpp | 61 ++++++++++++++++++++++++++++++++++++- core/db.h | 2 ++ core/dirs.cpp | 1 + core/item.h | 1 - core/session.cpp | 2 +- core/session.h | 2 +- html/fun_priv.html | 2 +- html/fun_ticket.html | 2 +- templates/dir.cpp | 6 ---- templates/patterncacher.cpp | 2 +- templates/templates.cpp | 3 +- templates/templates.h | 3 +- templates/ticket.cpp | 5 +++ 16 files changed, 137 insertions(+), 38 deletions(-) diff --git a/content/content.h b/content/content.h index a845a91..5452e65 100755 --- a/content/content.h +++ b/content/content.h @@ -50,6 +50,7 @@ class Content void FunEmacs(); void FunPriv(); + bool FunRmCheckAccess(); void FunRmDirRecursive(); void FunRmDir(); void FunRm(); @@ -116,6 +117,7 @@ class Content bool FunEditTicketCheckAccess(); void PostFunEditTicketLogAndRedirect(); + void EditTicketCheckFirstItem(); void EditTicketModTicket(); void EditTicketModDir(); void EditTicketModFirstItem(); diff --git a/content/editticket.cpp b/content/editticket.cpp index 63b574b..d6f51b4 100755 --- a/content/editticket.cpp +++ b/content/editticket.cpp @@ -29,6 +29,33 @@ return true; +void Content::EditTicketCheckFirstItem() +{ + if( request.session->done_status != Error::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 + SetUser(item); + PrepareUrl(item); + + request.session->done_status = db.AddItem(item); + + if( request.session->done_status == Error::ok ) + { + log << log2 << "Content: added the first item with content for the ticket, item.id: " << item.id << logend; + request.ticket.item_id = item.id; + } + } +} @@ -128,6 +155,7 @@ void Content::PostFunEditTicket() return; } + EditTicketCheckFirstItem(); EditTicketModTicket(); EditTicketModDir(); EditTicketModFirstItem(); diff --git a/content/rm.cpp b/content/rm.cpp index 63591d0..65456ef 100755 --- a/content/rm.cpp +++ b/content/rm.cpp @@ -15,10 +15,31 @@ +bool Content::FunRmCheckAccess() +{ + if( !request.is_item ) + { + if( !request.CanRemove(*request.dir_table.back()) ) + { + request.status = Error::permission_denied; + return false; + } + } + else + if( !request.CanRemove(request.item) ) + { + request.status = Error::permission_denied; + return false; + } + + +return true; +} + + + void Content::FunRmDirRecursive() { - data.dirs.MakePath(request.dir_table.back()->id, request.session->dir_old); - // this method deletes recursively all directories data.dirs.DeleteDir(request.dir_table.back()->id); @@ -53,12 +74,6 @@ void Content::FunRmDirRecursive() void Content::FunRmDir() { - if( !request.CanRemove(*request.dir_table.back()) ) - { - request.status = Error::permission_denied; - return; - } - if( request.param_table.empty() ) request.status = Error::permission_denied; else @@ -72,27 +87,17 @@ void Content::FunRmDir() } + void Content::FunRm() { - if( !request.is_item ) - { - FunRmDir(); + if( !FunRmCheckAccess() ) return; - } - if( !request.CanRemove(request.item) ) - { - request.status = Error::permission_denied; - return; - } - + if( !request.is_item ) + return FunRmDir(); if( request.param_table.empty() ) { - // we'll put some information about the deleted item (on the next page) - request.session->item = request.item; - - // !! zmienic interfejs dla db.DelItem if( db.DelItem( request.item ) ) { request.session->done_status = Error::ok; @@ -101,6 +106,10 @@ void Content::FunRm() if( data.mounts.pmount->type == Mount::thread ) db.EditThreadRemoveItem(request.item.parent_id); + else + if( data.mounts.pmount->type == Mount::ticket ) + db.EditTicketRemoveItem(request.item.id); + } else { diff --git a/core/db.cpp b/core/db.cpp index 547bf32..e3cd945 100755 --- a/core/db.cpp +++ b/core/db.cpp @@ -1103,6 +1103,7 @@ Error Db::DelDirById(long id) AssertConnection(); std::ostringstream query, query2; + // !! trzeba poprawic to usuwanie gdy beda hard linki query << "delete from core.content where content.id in (select content_id from core.item where parent_id='" << id << "');"; r = AssertQuery( query.str() ); AssertResultStatus(r, PGRES_COMMAND_OK); @@ -1226,7 +1227,7 @@ Error Db::DelItemCountContents(const Item & item, long & contents) contents = atol( AssertValue(r, 0, 0) ); - log << log1 << "counters: " << contents << logend; // !! + log << log2 << "counters: " << contents << logend; // !! nie potrzebne w logach } catch(const Error & e) { @@ -1909,3 +1910,61 @@ Error Db::EditTicketById(Ticket & ticket) return status; } + + +Error Db::EditTicketRemoveItem(long item_id) +{ + PGresult * r = 0; + Error status = Error::ok; + + try + { + AssertConnection(); + std::ostringstream query; + + query << "update core.ticket set item_id = '-1' where item_id='" << item_id << "';"; + + r = AssertQuery(query.str()); + AssertResultStatus(r, PGRES_COMMAND_OK); + } + catch(const Error & e) + { + status = e; + } + + ClearResult(r); + + +return status; +} + + +Error Db::RemoveTicket(long dir_id) +{ + PGresult * r = 0; + Error status = Error::ok; + + try + { + AssertConnection(); + std::ostringstream query; + query << "delete from core.ticket where dir_id='" << dir_id << "';"; + + const char * crows = PQcmdTuples(r); + if( crows ) + log << log2 << "Db: deleted " << atol(crows) << " rows from core.ticket" << logend; + + r = AssertQuery(query.str()); + AssertResultStatus(r, PGRES_COMMAND_OK); + } + catch(const Error & e) + { + status = e; + } + + ClearResult(r); + +return status; +} + + diff --git a/core/db.h b/core/db.h index 009b7c2..d58b39b 100755 --- a/core/db.h +++ b/core/db.h @@ -96,6 +96,8 @@ public: //bool IsTicket(long dir_id); Error AddTicket(Ticket & ticket); Error EditTicketById(Ticket & ticket); + Error EditTicketRemoveItem(long item_id); + Error RemoveTicket(long dir_id); protected: diff --git a/core/dirs.cpp b/core/dirs.cpp index 8f84461..8c8842c 100755 --- a/core/dirs.cpp +++ b/core/dirs.cpp @@ -271,6 +271,7 @@ void Dirs::DeleteDir(long id) dir_table.DelById(id); db.RemoveThread(id); + db.RemoveTicket(id); } diff --git a/core/item.h b/core/item.h index 75bd623..2f5d766 100755 --- a/core/item.h +++ b/core/item.h @@ -65,7 +65,6 @@ long default_item; // used by the database -// !! moze da sie w ogole z tego zrezygnowac? long content_id; diff --git a/core/session.cpp b/core/session.cpp index c06d617..1fc3d0c 100755 --- a/core/session.cpp +++ b/core/session.cpp @@ -41,7 +41,7 @@ void Session::Clear() new_session = true; spam_score = 0; - dir_old.clear(); +// dir_old.clear(); } diff --git a/core/session.h b/core/session.h index 7ab62d3..0d69a6b 100755 --- a/core/session.h +++ b/core/session.h @@ -60,7 +60,7 @@ struct Session Rebus::Item * rebus_item; bool rebus_checked; - std::string dir_old; + //std::string dir_old; int spam_score; diff --git a/html/fun_priv.html b/html/fun_priv.html index ae20e31..1edb319 100755 --- a/html/fun_priv.html +++ b/html/fun_priv.html @@ -28,7 +28,7 @@ - permissions: + {permissions}: diff --git a/html/fun_ticket.html b/html/fun_ticket.html index 856a41d..3bfff7e 100755 --- a/html/fun_ticket.html +++ b/html/fun_ticket.html @@ -33,7 +33,7 @@ [if-one ticket_is]
-

\[{edit}\]

+ [if-one ticket_can_edit]

\[{edit}\]

[end] [if-any ticket_type_tab][end] [if-any ticket_status_tab][end] diff --git a/templates/dir.cpp b/templates/dir.cpp index d8c4688..4ef9612 100755 --- a/templates/dir.cpp +++ b/templates/dir.cpp @@ -285,12 +285,6 @@ void dir_last_dates_equal(Info & i) -void dir_old(Info & i) -{ - HtmlEscape(i.out, request.session->dir_old); - -} - diff --git a/templates/patterncacher.cpp b/templates/patterncacher.cpp index 0bb57c5..6974d08 100755 --- a/templates/patterncacher.cpp +++ b/templates/patterncacher.cpp @@ -129,7 +129,7 @@ PatternTab::iterator i; if( i == pattern_tab.end() ) { - log << log2 << "PC: there is no such an item to delete, id: " << item.id << ", url: " << item.url << logend; + log << log3 << "PC: there is no such an item to delete, id: " << item.id << ", url: " << item.url << logend; return; } diff --git a/templates/templates.cpp b/templates/templates.cpp index 123c963..54f90bd 100755 --- a/templates/templates.cpp +++ b/templates/templates.cpp @@ -256,7 +256,7 @@ void Templates::CreateFunctions() functions.Insert("dir_last_date_modification", dir_last_date_modification); functions.Insert("dir_last_dates_equal", dir_last_dates_equal); - functions.Insert("dir_old", dir_old); + /* user @@ -348,6 +348,7 @@ void Templates::CreateFunctions() */ functions.Insert("ticket_is", ticket_is); functions.Insert("ticket_can_create", ticket_can_create); + functions.Insert("ticket_can_edit", ticket_can_edit); functions.Insert("ticket_type", ticket_type); functions.Insert("ticket_status", ticket_status); functions.Insert("ticket_priority", ticket_priority); diff --git a/templates/templates.h b/templates/templates.h index 06567df..0c167ea 100755 --- a/templates/templates.h +++ b/templates/templates.h @@ -170,8 +170,6 @@ namespace TemplatesFunctions void dir_last_date_modification(Info & i); void dir_last_dates_equal(Info & i); - void dir_old(Info & i); - /* user @@ -258,6 +256,7 @@ namespace TemplatesFunctions */ void ticket_is(Info & i); // !! change to is_ticket lub na ticket_defined void ticket_can_create(Info & i); + void ticket_can_edit(Info & i); void ticket_type(Info & i); void ticket_status(Info & i); void ticket_priority(Info & i); diff --git a/templates/ticket.cpp b/templates/ticket.cpp index 2d19256..659248c 100755 --- a/templates/ticket.cpp +++ b/templates/ticket.cpp @@ -32,6 +32,11 @@ void ticket_can_create(Info & i) } +void ticket_can_edit(Info & i) +{ + i.result = request.CanEditTicket(); +} + void ticket_type(Info & i) {
{ticket_info_type}:[ticket_type]
{ticket_info_status}:[ticket_status]