added: 'rm' function can remove auth content now
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@597 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
6fbcffe63b
commit
aff4cc516e
|
@ -91,10 +91,20 @@ class Content
|
||||||
|
|
||||||
void FunCKEditor();
|
void FunCKEditor();
|
||||||
|
|
||||||
bool FunRmCheckAccess();
|
|
||||||
void FunRmDirRecursive();
|
/*
|
||||||
void FunRmDir();
|
rm
|
||||||
|
*/
|
||||||
|
bool RemoveCheckAccess();
|
||||||
|
void RemoveAllDirs();
|
||||||
|
void RemoveAllDirs(long dir_id);
|
||||||
|
void RemoveDir();
|
||||||
|
void RemoveAuthPrepareQuery();
|
||||||
|
void RemoveAuth(Item & item);
|
||||||
|
void RemoveFile();
|
||||||
void FunRm();
|
void FunRm();
|
||||||
|
Db::ItemQuery rm_auth_iq;
|
||||||
|
|
||||||
|
|
||||||
void FunNode();
|
void FunNode();
|
||||||
void FunMkdir();
|
void FunMkdir();
|
||||||
|
|
|
@ -275,6 +275,8 @@ void Content::MoveAuthContentOfDir(const Item & item)
|
||||||
|
|
||||||
for(size_t i=0 ; i<mv_auth.size() ; ++i)
|
for(size_t i=0 ; i<mv_auth.size() ; ++i)
|
||||||
MoveAuth(mv_auth[i]);
|
MoveAuth(mv_auth[i]);
|
||||||
|
|
||||||
|
mv_auth.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -323,7 +325,7 @@ void Content::MoveDir(Item & item, bool redirect)
|
||||||
void Content::PostFunMv()
|
void Content::PostFunMv()
|
||||||
{
|
{
|
||||||
if( MoveCheckAccessFrom() &&
|
if( MoveCheckAccessFrom() &&
|
||||||
MoveParseDir(mv_dir_id, mv_dir, mv_file) &&
|
MoveParseDir(mv_dir_id, mv_dir, mv_file) &&
|
||||||
MoveCheckAccessTo(mv_dir_id) &&
|
MoveCheckAccessTo(mv_dir_id) &&
|
||||||
MoveCheckMountPoints(mv_dir_id) )
|
MoveCheckMountPoints(mv_dir_id) )
|
||||||
{
|
{
|
||||||
|
|
168
content/rm.cpp
168
content/rm.cpp
|
@ -7,15 +7,16 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
#include <errno.h>
|
||||||
#include "content.h"
|
#include "content.h"
|
||||||
#include "../core/request.h"
|
#include "../core/request.h"
|
||||||
#include "../core/error.h"
|
#include "../core/error.h"
|
||||||
#include "../core/db.h"
|
|
||||||
#include "../core/data.h"
|
#include "../core/data.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Content::FunRmCheckAccess()
|
bool Content::RemoveCheckAccess()
|
||||||
{
|
{
|
||||||
if( !request.is_item )
|
if( !request.is_item )
|
||||||
{
|
{
|
||||||
|
@ -38,19 +39,61 @@ return true;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Content::FunRmDirRecursive()
|
void Content::RemoveAuthPrepareQuery()
|
||||||
{
|
{
|
||||||
// this method deletes recursively all directories
|
rm_auth_iq.SetAll(true, false);
|
||||||
data.dirs.DeleteDir(request.dir_table.back()->id);
|
|
||||||
|
|
||||||
|
rm_auth_iq.sel_parent_id = true;
|
||||||
|
rm_auth_iq.sel_type = true;
|
||||||
|
rm_auth_iq.sel_auth = true;
|
||||||
|
|
||||||
|
rm_auth_iq.WhereType(Item::file);
|
||||||
|
rm_auth_iq.WhereAuth(Item::auth_none, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Content::RemoveAllDirs(long dir_id)
|
||||||
|
{
|
||||||
|
DirContainer::ParentIterator pnext, p = data.dirs.FindFirstParent(dir_id);
|
||||||
|
|
||||||
|
for( ; p != data.dirs.ParentEnd() ; p = pnext )
|
||||||
|
{
|
||||||
|
// this iterator p will be deleted by the next DeleteDir(p->second->id)
|
||||||
|
// (the next iterator we must calculate beforehand)
|
||||||
|
pnext = data.dirs.NextParent(p);
|
||||||
|
RemoveAllDirs(p->second->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
rm_auth_iq.WhereParentId(dir_id);
|
||||||
|
db.GetItems(request.item_table, rm_auth_iq);
|
||||||
|
|
||||||
|
for(size_t i=0 ; i<request.item_table.size() ; ++i)
|
||||||
|
RemoveAuth(request.item_table[i]);
|
||||||
|
|
||||||
|
if( db.DelDirById(dir_id) == WINIX_ERR_OK )
|
||||||
|
{
|
||||||
|
data.dirs.DelDir(dir_id);
|
||||||
|
|
||||||
|
db.RemoveThread(dir_id);
|
||||||
|
db.RemoveTicket(dir_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Content::RemoveAllDirs()
|
||||||
|
{
|
||||||
|
RemoveAuthPrepareQuery();
|
||||||
|
|
||||||
|
// this method deletes recursively all directories
|
||||||
|
RemoveAllDirs(request.dir_table.back()->id);
|
||||||
request.dir_table.erase(--request.dir_table.end());
|
request.dir_table.erase(--request.dir_table.end());
|
||||||
|
|
||||||
if( request.dir_table.empty() )
|
if( request.dir_table.empty() )
|
||||||
{
|
{
|
||||||
// we have deleted the root directory
|
// we have deleted the root directory
|
||||||
|
data.dirs.CheckRootDir(); // adding a new root dir
|
||||||
data.dirs.CheckRootDir();
|
|
||||||
|
|
||||||
Item * proot = data.dirs.GetRootDir();
|
Item * proot = data.dirs.GetRootDir();
|
||||||
|
|
||||||
if( proot )
|
if( proot )
|
||||||
|
@ -62,63 +105,100 @@ void Content::FunRmDirRecursive()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RedirectToLastDir();
|
||||||
// redirect to the last valid directory
|
|
||||||
RedirectTo(**(--request.dir_table.end()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Content::FunRmDir()
|
void Content::RemoveDir()
|
||||||
{
|
{
|
||||||
if( request.param_table.empty() )
|
if( request.param_table.empty() )
|
||||||
request.status = WINIX_ERR_PERMISSION_DENIED;
|
request.status = WINIX_ERR_PERMISSION_DENIED; // use parameter "r" for removing a directory
|
||||||
else
|
|
||||||
if( request.IsParam("confirm") )
|
|
||||||
return;
|
|
||||||
else
|
else
|
||||||
if( request.IsParam("r") )
|
if( request.IsParam("r") )
|
||||||
FunRmDirRecursive();
|
RemoveAllDirs();
|
||||||
else
|
else
|
||||||
request.status = WINIX_ERR_UNKNOWN_PARAM;
|
request.status = WINIX_ERR_UNKNOWN_PARAM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Content::FunRm()
|
void Content::RemoveAuth(Item & item)
|
||||||
{
|
{
|
||||||
if( !FunRmCheckAccess() )
|
if( item.auth_path.empty() )
|
||||||
return;
|
|
||||||
|
|
||||||
if( !request.is_item )
|
|
||||||
return FunRmDir();
|
|
||||||
|
|
||||||
if( request.param_table.empty() )
|
|
||||||
{
|
{
|
||||||
if( db.DelItem( request.item ) )
|
log << log1 << "Content: can't remove a static file: auth_path is empty" << logend;
|
||||||
{
|
return;
|
||||||
log << log2 << "Content: deleted item: subject: " << request.item.subject << ", id: " << request.item.id << logend;
|
}
|
||||||
TemplatesFunctions::pattern_cacher.DeletePattern(request.item);
|
|
||||||
|
|
||||||
if( data.mounts.pmount->type == Mount::thread )
|
if( remove(item.auth_path.c_str()) == 0 )
|
||||||
db.EditThreadRemoveItem(request.item.parent_id);
|
{
|
||||||
else
|
log << log1 << "Content: removed static file: " << item.auth_path << logend;
|
||||||
if( data.mounts.pmount->type == Mount::ticket )
|
item.auth_path.clear();
|
||||||
db.EditTicketRemoveItem(request.item.id);
|
item.auth = Item::auth_none;
|
||||||
|
// we don't store it to db (will be removed or is removed already)
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
request.status = WINIX_ERR_NO_ITEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
RedirectTo(*request.dir_table.back());
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( !request.IsParam("confirm") )
|
int err = errno;
|
||||||
request.status = WINIX_ERR_UNKNOWN_PARAM;
|
|
||||||
|
log << log1 << "Content: can't remove a file: " << item.auth_path;
|
||||||
|
log.SystemErr(err);
|
||||||
|
log << logend;
|
||||||
|
|
||||||
|
request.status = WINIX_ERR_PERMISSION_DENIED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Content::RemoveFile()
|
||||||
|
{
|
||||||
|
// for safety we check if param_table is empty
|
||||||
|
// a user can use "confirm" but can make a mistake when typing
|
||||||
|
if( !request.param_table.empty() )
|
||||||
|
{
|
||||||
|
request.status = WINIX_ERR_UNKNOWN_PARAM;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if( db.DelItem( request.item ) )
|
||||||
|
{
|
||||||
|
log << log2 << "Content: deleted item: subject: " << request.item.subject << ", id: " << request.item.id << logend;
|
||||||
|
TemplatesFunctions::pattern_cacher.DeletePattern(request.item);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
if( request.item.auth != Item::auth_none )
|
||||||
|
RemoveAuth(request.item);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
request.status = WINIX_ERR_NO_ITEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
RedirectToLastDir();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Content::FunRm()
|
||||||
|
{
|
||||||
|
if( !RemoveCheckAccess() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
if( request.IsParam("confirm") )
|
||||||
|
return; // show confirmation dialog
|
||||||
|
|
||||||
|
if( request.is_item )
|
||||||
|
RemoveFile();
|
||||||
|
else
|
||||||
|
RemoveDir();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
16
core/db.cpp
16
core/db.cpp
|
@ -1352,8 +1352,6 @@ Error Db::DelItemCountContents(const Item & item, long & contents)
|
||||||
AssertResultStatus(r, PGRES_TUPLES_OK);
|
AssertResultStatus(r, PGRES_TUPLES_OK);
|
||||||
|
|
||||||
contents = atol( AssertValue(r, 0, 0) );
|
contents = atol( AssertValue(r, 0, 0) );
|
||||||
|
|
||||||
log << log2 << "counters: " << contents << logend; // !! nie potrzebne w logach
|
|
||||||
}
|
}
|
||||||
catch(const Error & e)
|
catch(const Error & e)
|
||||||
{
|
{
|
||||||
|
@ -1830,8 +1828,13 @@ Error Db::RemoveThread(long dir_id)
|
||||||
query << "delete from core.thread where dir_id='" << dir_id << "';";
|
query << "delete from core.thread where dir_id='" << dir_id << "';";
|
||||||
|
|
||||||
const char * crows = PQcmdTuples(r);
|
const char * crows = PQcmdTuples(r);
|
||||||
|
long rows = 0;
|
||||||
|
|
||||||
if( crows )
|
if( crows )
|
||||||
log << log2 << "Db: deleted " << atol(crows) << " rows from core.thread" << logend;
|
rows = atol(crows);
|
||||||
|
|
||||||
|
if( rows > 0 )
|
||||||
|
log << log2 << "Db: deleted " << rows << " rows from core.thread" << logend;
|
||||||
|
|
||||||
r = AssertQuery(query.str());
|
r = AssertQuery(query.str());
|
||||||
AssertResultStatus(r, PGRES_COMMAND_OK);
|
AssertResultStatus(r, PGRES_COMMAND_OK);
|
||||||
|
@ -2081,8 +2084,13 @@ Error Db::RemoveTicket(long dir_id)
|
||||||
query << "delete from core.ticket where dir_id='" << dir_id << "';";
|
query << "delete from core.ticket where dir_id='" << dir_id << "';";
|
||||||
|
|
||||||
const char * crows = PQcmdTuples(r);
|
const char * crows = PQcmdTuples(r);
|
||||||
|
long rows = 0;
|
||||||
|
|
||||||
if( crows )
|
if( crows )
|
||||||
log << log2 << "Db: deleted " << atol(crows) << " rows from core.ticket" << logend;
|
rows = atol(crows);
|
||||||
|
|
||||||
|
if( rows > 0 )
|
||||||
|
log << log2 << "Db: deleted " << rows << " rows from core.ticket" << logend;
|
||||||
|
|
||||||
r = AssertQuery(query.str());
|
r = AssertQuery(query.str());
|
||||||
AssertResultStatus(r, PGRES_COMMAND_OK);
|
AssertResultStatus(r, PGRES_COMMAND_OK);
|
||||||
|
|
|
@ -387,31 +387,14 @@ void Dirs::SplitPath(const std::string & path, std::string & dir, std::string &
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool Dirs::DelDir(long dir_id)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// !! przeniesc to do rm
|
|
||||||
// mamy juz interfejs do chodzenia po parentach
|
|
||||||
void Dirs::DeleteDir(long id)
|
|
||||||
{
|
{
|
||||||
DirContainer::ParentIterator pnext, p = dir_table.FindFirstParent(id);
|
return dir_table.DelById(dir_id);
|
||||||
|
|
||||||
for( ; p != dir_table.ParentEnd() ; p = pnext )
|
|
||||||
{
|
|
||||||
// this iterator p will be deleted by the next DeleteDir(p->second->id)
|
|
||||||
// (the next iterator we must calculate beforehand)
|
|
||||||
pnext = dir_table.NextParent(p);
|
|
||||||
|
|
||||||
DeleteDir(p->second->id);
|
|
||||||
}
|
|
||||||
|
|
||||||
if( db.DelDirById(id) == WINIX_ERR_OK )
|
|
||||||
dir_table.DelById(id);
|
|
||||||
|
|
||||||
db.RemoveThread(id);
|
|
||||||
db.RemoveTicket(id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@ public:
|
||||||
bool MakePath(long dir_id, std::string & path);
|
bool MakePath(long dir_id, std::string & path);
|
||||||
bool ChangeParent(long dir_id, long new_parent_id);
|
bool ChangeParent(long dir_id, long new_parent_id);
|
||||||
bool HasParent(long dir_id, long parent_id);
|
bool HasParent(long dir_id, long parent_id);
|
||||||
|
bool DelDir(long dir_id);
|
||||||
|
|
||||||
int AnalyzePath(const std::string & path, long & dir_id, std::string & dir, std::string & file);
|
int AnalyzePath(const std::string & path, long & dir_id, std::string & dir, std::string & file);
|
||||||
static void SplitPath(const std::string & path, std::string & dir, std::string & file);
|
static void SplitPath(const std::string & path, std::string & dir, std::string & file);
|
||||||
|
@ -53,7 +54,6 @@ public:
|
||||||
Item * GetDir(long id);
|
Item * GetDir(long id);
|
||||||
Item * AddDir(const Item & item);
|
Item * AddDir(const Item & item);
|
||||||
|
|
||||||
void DeleteDir(long id);
|
|
||||||
void CheckRootDir();
|
void CheckRootDir();
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
[include "error.html"]
|
[include "error.html"]
|
||||||
|
|
||||||
<form id="additem" method="post" action="[doc_base_url][dir][if-one item_is][item_url]/[end]upload/noredirect/ckeditor_upload" enctype="multipart/form-data">
|
<form id="additem" method="post" action="[doc_base_url][dir][if-one item_is][item_url]/[end]upload" enctype="multipart/form-data">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>{upload_form_legend}</legend>
|
<legend>{upload_form_legend}</legend>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue