added: forum

added: mount params can have arguments (in parentheses)
added: mount params: withheader, withinfo, restrictcreatethread, only_root_can_remove,
       can_use_emacs_on(level), can_use_mkdir_on(level), 
added: table Item has 'subject' column now
removed: column 'subject' from table Content




git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@505 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2009-06-05 20:29:06 +00:00
parent 3d001e7458
commit 1eb42446f8
38 changed files with 1357 additions and 369 deletions

View File

@ -1,25 +1,25 @@
# DO NOT DELETE
cat.o: content.h ../core/item.h ../templates/templates.h ../../ezc/src/ezc.h
cat.o: ../templates/patterncacher.h ../app/templates.h ../core/request.h
cat.o: ../core/requesttypes.h ../core/session.h ../core/done.h ../core/item.h
cat.o: ../core/error.h ../core/log.h ../core/user.h ../core/function.h
cat.o: ../core/thread.h ../core/error.h
cat.o: ../templates/patterncacher.h ../app/templates.h ../core/thread.h
cat.o: ../core/request.h ../core/requesttypes.h ../core/session.h
cat.o: ../core/done.h ../core/item.h ../core/error.h ../core/log.h
cat.o: ../core/user.h ../core/function.h ../core/thread.h ../core/error.h
content.o: content.h ../core/item.h ../templates/templates.h
content.o: ../../ezc/src/ezc.h ../templates/patterncacher.h
content.o: ../app/templates.h ../core/request.h ../core/requesttypes.h
content.o: ../core/session.h ../core/done.h ../core/item.h ../core/error.h
content.o: ../core/log.h ../core/user.h ../core/function.h ../core/thread.h
content.o: ../core/error.h ../core/db.h ../core/group.h
content.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/data.h
content.o: ../core/dirs.h ../core/users.h ../core/groups.h
content.o: ../app/templates.h ../core/thread.h ../core/request.h
content.o: ../core/requesttypes.h ../core/session.h ../core/done.h
content.o: ../core/item.h ../core/error.h ../core/log.h ../core/user.h
content.o: ../core/function.h ../core/thread.h ../core/error.h ../core/db.h
content.o: ../core/group.h ../core/dircontainer.h ../core/ugcontainer.h
content.o: ../core/data.h ../core/dirs.h ../core/users.h ../core/groups.h
content.o: ../core/functions.h ../core/lastcontainer.h ../core/mounts.h
content.o: ../core/mount.h ../app/content.h
content.o: ../core/mount.h ../app/content.h ../core/misc.h
createthread.o: content.h ../core/item.h ../templates/templates.h
createthread.o: ../../ezc/src/ezc.h ../templates/patterncacher.h
createthread.o: ../app/templates.h ../core/request.h ../core/requesttypes.h
createthread.o: ../core/session.h ../core/done.h ../core/item.h
createthread.o: ../core/error.h ../core/log.h ../core/user.h
createthread.o: ../app/templates.h ../core/thread.h ../core/request.h
createthread.o: ../core/requesttypes.h ../core/session.h ../core/done.h
createthread.o: ../core/item.h ../core/error.h ../core/log.h ../core/user.h
createthread.o: ../core/function.h ../core/thread.h ../core/error.h
createthread.o: ../core/db.h ../core/group.h ../core/dircontainer.h
createthread.o: ../core/ugcontainer.h ../core/mount.h ../core/data.h
@ -28,93 +28,94 @@ createthread.o: ../core/functions.h ../core/lastcontainer.h ../core/mounts.h
createthread.o: ../core/mount.h
default.o: content.h ../core/item.h ../templates/templates.h
default.o: ../../ezc/src/ezc.h ../templates/patterncacher.h
default.o: ../app/templates.h ../core/request.h ../core/requesttypes.h
default.o: ../core/session.h ../core/done.h ../core/item.h ../core/error.h
default.o: ../core/log.h ../core/user.h ../core/function.h ../core/thread.h
default.o: ../core/error.h ../core/db.h ../core/group.h
default.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/data.h
default.o: ../core/dirs.h ../core/users.h ../core/groups.h
default.o: ../app/templates.h ../core/thread.h ../core/request.h
default.o: ../core/requesttypes.h ../core/session.h ../core/done.h
default.o: ../core/item.h ../core/error.h ../core/log.h ../core/user.h
default.o: ../core/function.h ../core/thread.h ../core/error.h ../core/db.h
default.o: ../core/group.h ../core/dircontainer.h ../core/ugcontainer.h
default.o: ../core/data.h ../core/dirs.h ../core/users.h ../core/groups.h
default.o: ../core/functions.h ../core/lastcontainer.h ../core/mounts.h
default.o: ../core/mount.h
emacs.o: content.h ../core/item.h ../templates/templates.h
emacs.o: ../../ezc/src/ezc.h ../templates/patterncacher.h ../app/templates.h
emacs.o: ../core/request.h ../core/requesttypes.h ../core/session.h
emacs.o: ../core/done.h ../core/item.h ../core/error.h ../core/log.h
emacs.o: ../core/user.h ../core/function.h ../core/thread.h ../core/error.h
emacs.o: ../core/misc.h ../core/db.h ../core/group.h ../core/dircontainer.h
emacs.o: ../core/thread.h ../core/request.h ../core/requesttypes.h
emacs.o: ../core/session.h ../core/done.h ../core/item.h ../core/error.h
emacs.o: ../core/log.h ../core/user.h ../core/function.h ../core/thread.h
emacs.o: ../core/error.h ../core/db.h ../core/group.h ../core/dircontainer.h
emacs.o: ../core/ugcontainer.h ../core/data.h ../core/dirs.h ../core/users.h
emacs.o: ../core/groups.h ../core/functions.h ../core/lastcontainer.h
emacs.o: ../core/mounts.h ../core/mount.h
last.o: content.h ../core/item.h ../templates/templates.h ../../ezc/src/ezc.h
last.o: ../templates/patterncacher.h ../app/templates.h
last.o: ../templates/patterncacher.h ../app/templates.h ../core/thread.h
login.o: content.h ../core/item.h ../templates/templates.h
login.o: ../../ezc/src/ezc.h ../templates/patterncacher.h ../app/templates.h
login.o: ../core/request.h ../core/requesttypes.h ../core/session.h
login.o: ../core/done.h ../core/item.h ../core/error.h ../core/log.h
login.o: ../core/user.h ../core/function.h ../core/thread.h ../core/error.h
login.o: ../core/db.h ../core/group.h ../core/dircontainer.h
login.o: ../core/thread.h ../core/request.h ../core/requesttypes.h
login.o: ../core/session.h ../core/done.h ../core/item.h ../core/error.h
login.o: ../core/log.h ../core/user.h ../core/function.h ../core/thread.h
login.o: ../core/error.h ../core/db.h ../core/group.h ../core/dircontainer.h
login.o: ../core/ugcontainer.h ../core/data.h ../core/dirs.h ../core/users.h
login.o: ../core/groups.h ../core/functions.h ../core/lastcontainer.h
login.o: ../core/mounts.h ../core/mount.h
logout.o: content.h ../core/item.h ../templates/templates.h
logout.o: ../../ezc/src/ezc.h ../templates/patterncacher.h ../app/templates.h
logout.o: ../core/request.h ../core/requesttypes.h ../core/session.h
logout.o: ../core/done.h ../core/item.h ../core/error.h ../core/log.h
logout.o: ../core/user.h ../core/function.h ../core/thread.h ../core/data.h
logout.o: ../core/dirs.h ../core/dircontainer.h ../core/users.h
logout.o: ../core/ugcontainer.h ../core/groups.h ../core/group.h
logout.o: ../core/functions.h ../core/lastcontainer.h ../core/mounts.h
logout.o: ../core/mount.h
logout.o: ../core/thread.h ../core/request.h ../core/requesttypes.h
logout.o: ../core/session.h ../core/done.h ../core/item.h ../core/error.h
logout.o: ../core/log.h ../core/user.h ../core/function.h ../core/thread.h
logout.o: ../core/data.h ../core/dirs.h ../core/dircontainer.h
logout.o: ../core/users.h ../core/ugcontainer.h ../core/groups.h
logout.o: ../core/group.h ../core/functions.h ../core/lastcontainer.h
logout.o: ../core/mounts.h ../core/mount.h
ls.o: content.h ../core/item.h ../templates/templates.h ../../ezc/src/ezc.h
ls.o: ../templates/patterncacher.h ../app/templates.h ../core/request.h
ls.o: ../core/requesttypes.h ../core/session.h ../core/done.h ../core/item.h
ls.o: ../core/error.h ../core/log.h ../core/user.h ../core/function.h
ls.o: ../core/thread.h ../core/db.h ../core/group.h ../core/dircontainer.h
ls.o: ../core/ugcontainer.h
ls.o: ../templates/patterncacher.h ../app/templates.h ../core/thread.h
ls.o: ../core/request.h ../core/requesttypes.h ../core/session.h
ls.o: ../core/done.h ../core/item.h ../core/error.h ../core/log.h
ls.o: ../core/user.h ../core/function.h ../core/thread.h ../core/db.h
ls.o: ../core/group.h ../core/dircontainer.h ../core/ugcontainer.h
mkdir.o: content.h ../core/item.h ../templates/templates.h
mkdir.o: ../../ezc/src/ezc.h ../templates/patterncacher.h ../app/templates.h
mkdir.o: ../core/request.h ../core/requesttypes.h ../core/session.h
mkdir.o: ../core/done.h ../core/item.h ../core/error.h ../core/log.h
mkdir.o: ../core/user.h ../core/function.h ../core/thread.h ../core/error.h
mkdir.o: ../core/db.h ../core/group.h ../core/dircontainer.h
mkdir.o: ../core/thread.h ../core/request.h ../core/requesttypes.h
mkdir.o: ../core/session.h ../core/done.h ../core/item.h ../core/error.h
mkdir.o: ../core/log.h ../core/user.h ../core/function.h ../core/thread.h
mkdir.o: ../core/error.h ../core/db.h ../core/group.h ../core/dircontainer.h
mkdir.o: ../core/ugcontainer.h ../core/data.h ../core/dirs.h ../core/users.h
mkdir.o: ../core/groups.h ../core/functions.h ../core/lastcontainer.h
mkdir.o: ../core/mounts.h ../core/mount.h
node.o: content.h ../core/item.h ../templates/templates.h ../../ezc/src/ezc.h
node.o: ../templates/patterncacher.h ../app/templates.h ../core/request.h
node.o: ../core/requesttypes.h ../core/session.h ../core/done.h
node.o: ../core/item.h ../core/error.h ../core/log.h ../core/user.h
node.o: ../core/function.h ../core/thread.h
node.o: ../templates/patterncacher.h ../app/templates.h ../core/thread.h
node.o: ../core/request.h ../core/requesttypes.h ../core/session.h
node.o: ../core/done.h ../core/item.h ../core/error.h ../core/log.h
node.o: ../core/user.h ../core/function.h ../core/thread.h
priv.o: content.h ../core/item.h ../templates/templates.h ../../ezc/src/ezc.h
priv.o: ../templates/patterncacher.h ../app/templates.h ../core/request.h
priv.o: ../core/requesttypes.h ../core/session.h ../core/done.h
priv.o: ../core/item.h ../core/error.h ../core/log.h ../core/user.h
priv.o: ../core/function.h ../core/thread.h ../core/error.h ../core/db.h
priv.o: ../core/group.h ../core/dircontainer.h ../core/ugcontainer.h
priv.o: ../core/data.h ../core/dirs.h ../core/users.h ../core/groups.h
priv.o: ../core/functions.h ../core/lastcontainer.h ../core/mounts.h
priv.o: ../core/mount.h
priv.o: ../templates/patterncacher.h ../app/templates.h ../core/thread.h
priv.o: ../core/request.h ../core/requesttypes.h ../core/session.h
priv.o: ../core/done.h ../core/item.h ../core/error.h ../core/log.h
priv.o: ../core/user.h ../core/function.h ../core/thread.h ../core/error.h
priv.o: ../core/db.h ../core/group.h ../core/dircontainer.h
priv.o: ../core/ugcontainer.h ../core/data.h ../core/dirs.h ../core/users.h
priv.o: ../core/groups.h ../core/functions.h ../core/lastcontainer.h
priv.o: ../core/mounts.h ../core/mount.h
rm.o: content.h ../core/item.h ../templates/templates.h ../../ezc/src/ezc.h
rm.o: ../templates/patterncacher.h ../app/templates.h ../core/request.h
rm.o: ../core/requesttypes.h ../core/session.h ../core/done.h ../core/item.h
rm.o: ../core/error.h ../core/log.h ../core/user.h ../core/function.h
rm.o: ../core/thread.h ../core/error.h ../core/db.h ../core/group.h
rm.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/data.h
rm.o: ../core/dirs.h ../core/users.h ../core/groups.h ../core/functions.h
rm.o: ../core/lastcontainer.h ../core/mounts.h ../core/mount.h
rm.o: ../templates/patterncacher.h ../app/templates.h ../core/thread.h
rm.o: ../core/request.h ../core/requesttypes.h ../core/session.h
rm.o: ../core/done.h ../core/item.h ../core/error.h ../core/log.h
rm.o: ../core/user.h ../core/function.h ../core/thread.h ../core/error.h
rm.o: ../core/db.h ../core/group.h ../core/dircontainer.h
rm.o: ../core/ugcontainer.h ../core/data.h ../core/dirs.h ../core/users.h
rm.o: ../core/groups.h ../core/functions.h ../core/lastcontainer.h
rm.o: ../core/mounts.h ../core/mount.h
run.o: content.h ../core/item.h ../templates/templates.h ../../ezc/src/ezc.h
run.o: ../templates/patterncacher.h ../app/templates.h ../core/request.h
run.o: ../core/requesttypes.h ../core/session.h ../core/done.h ../core/item.h
run.o: ../core/error.h ../core/log.h ../core/user.h ../core/function.h
run.o: ../core/thread.h ../core/error.h
run.o: ../templates/patterncacher.h ../app/templates.h ../core/thread.h
run.o: ../core/request.h ../core/requesttypes.h ../core/session.h
run.o: ../core/done.h ../core/item.h ../core/error.h ../core/log.h
run.o: ../core/user.h ../core/function.h ../core/thread.h ../core/error.h
thread.o: content.h ../core/item.h ../templates/templates.h
thread.o: ../../ezc/src/ezc.h ../templates/patterncacher.h ../app/templates.h
thread.o: ../core/request.h ../core/requesttypes.h ../core/session.h
thread.o: ../core/done.h ../core/item.h ../core/error.h ../core/log.h
thread.o: ../core/user.h ../core/function.h ../core/thread.h ../core/db.h
thread.o: ../core/group.h ../core/dircontainer.h ../core/ugcontainer.h
thread.o: ../core/data.h ../core/dirs.h ../core/users.h ../core/groups.h
thread.o: ../core/functions.h ../core/lastcontainer.h ../core/mounts.h
thread.o: ../core/mount.h ../core/mount.h
thread.o: ../core/thread.h ../core/request.h ../core/requesttypes.h
thread.o: ../core/session.h ../core/done.h ../core/item.h ../core/error.h
thread.o: ../core/log.h ../core/user.h ../core/function.h ../core/thread.h
thread.o: ../core/db.h ../core/group.h ../core/dircontainer.h
thread.o: ../core/ugcontainer.h ../core/data.h ../core/dirs.h ../core/users.h
thread.o: ../core/groups.h ../core/functions.h ../core/lastcontainer.h
thread.o: ../core/mounts.h ../core/mount.h ../core/mount.h
who.o: content.h ../core/item.h ../templates/templates.h ../../ezc/src/ezc.h
who.o: ../templates/patterncacher.h ../app/templates.h
who.o: ../templates/patterncacher.h ../app/templates.h ../core/thread.h

View File

@ -13,7 +13,7 @@
#include "../core/db.h"
#include "../core/data.h"
#include "../app/content.h"
#include "../core/misc.h"
bool Content::Init()
@ -59,9 +59,7 @@ void Content::SetDefaultFunctionForFile()
void Content::SetDefaultFunctionForDir()
{
Mount mount = data.mounts.GetCurrentMountPoint();
if( mount.type == Mount::thread )
if( data.mounts.CurrentMountType() == Mount::thread )
{
request.pfunction = data.functions.GetFunction(FUN_THREAD);
@ -341,15 +339,35 @@ void Content::ReadAdditionalInfo()
if( request.dir_table.empty() )
return;
Mount mount = data.mounts.GetCurrentMountPoint();
if( mount.type == Mount::thread )
if( data.mounts.CurrentMountType() == Mount::thread )
{
db.GetThreadByDirId(request.dir_table.back()->id, request.thread);
if( db.GetThreadByDirId(request.dir_table.back()->id, request.thread) == Error::ok )
request.is_thread = true;
}
}
void Content::PrepareUrl(Item & item)
{
TrimWhite(item.url);
if( item.url.empty() )
item.url = item.subject; // if the subject is empty then the url will be corrected by CorrectUrl()
CorrectUrl(item);
if( data.functions.GetFunction(item.url) )
{
// the name provided by an user is the same as a name of a function
// we add one underscore character at the beginning
// names of functions should not begin with an underscore '_'
// and we can simply add one '_' at the beginning
// and the name will be unique
item.url.insert(item.url.begin(), '_');
}
}

View File

@ -16,7 +16,7 @@
#include "../core/item.h"
#include "../templates/templates.h"
#include "../core/thread.h"
class Content
{
@ -55,6 +55,8 @@ class Content
void FunRun();
void FunWho();
void FunLast();
static bool FunThreadSort(const Thread & t1, const Thread & t2);
void FunThread();
void FunCreateThread();
@ -62,10 +64,11 @@ class Content
void PostFunEmacsAdd();
void PostFunEmacsEdit(bool with_url);
void PostFunEmacs();
void PostFunMkdir(bool add_to_dir_table = false);
void PostFunMkdir(bool add_to_dir_table = false, int mask = 0755 );
long PostFunDefaultParsePath();
void PostFunDefault();
void PostFunPriv();
void PostFunPriv(Item & item);
bool FunCreateThreadCheckAccess();
void PostFunCreateThread();

View File

@ -15,18 +15,9 @@
#include "../core/data.h"
bool Content::FunCreateThreadCheckAccess()
{
Mount mount = data.mounts.GetCurrentMountPoint();
if( mount.type != Mount::thread )
{
request.status = Error::permision_denied;
return false;
}
if( !request.HasWriteAccess(*request.dir_table.back()) || request.is_item )
if( !request.CanCreateThread() )
{
request.status = Error::permision_denied;
return false;
@ -42,28 +33,35 @@ void Content::PostFunCreateThread()
if( !FunCreateThreadCheckAccess() )
return;
request.post_table.insert( std::make_pair(std::string("url"), std::string()) ); // !! tymczasowo, zrobic aby mkdir i emacs nie rzucaly wyjatkiem gdy nie ma url zdefiniowanego
PostFunMkdir(true);
request.thread.parent_id = request.dir_table.back()->id;
PostFunMkdir(true, 0777); // !! tymczasowo 777 aby wszyscy mogli wysylac posty
if( request.session->done_status == Error::ok )
{
request.thread.dir_id = request.dir_table.back()->id;
request.thread.subject = request.PostVar("subject");
request.thread.closed = false;
request.session->done_status = db.AddThread(request.thread);
PostFunEmacs();
if( request.session->done_status == Error::ok )
{
request.thread.dir_id = request.dir_table.back()->id;
request.thread.closed = false;
request.thread.items = 1;
request.thread.last_item = request.item; // set by PostFunEmacs()
request.session->done_status = db.AddThread(request.thread);
}
if( request.session->done_status == Error::ok )
{
PostFunEmacs();
if( request.session->done_status == Error::ok )
{
request.session->done = Done::added_thread;
RedirectTo(*request.dir_table.back());
}
request.session->done = Done::added_thread;
RedirectTo(*request.dir_table.back());
}
}
}
@ -75,6 +73,8 @@ void Content::PostFunCreateThread()
void Content::FunCreateThread()
{
FunCreateThreadCheckAccess();
TemplatesFunctions::thread_show_edit_subject_var = true; // !! tymczasowe rozwiazanie
}

View File

@ -10,7 +10,6 @@
#include "content.h"
#include "../core/request.h"
#include "../core/error.h"
#include "../core/misc.h"
#include "../core/db.h"
#include "../core/data.h"
@ -18,22 +17,6 @@
void Content::PrepareUrl(Item & item)
{
CorrectUrl(item);
if( data.functions.GetFunction(item.url) )
{
// the name provided by an user is the same as a name of a function
// we add one underscore character at the beginning
// names of functions should not begin with an underscore '_'
// and we can simply add one '_' at the beginning
// and the name will be unique
item.url.insert(item.url.begin(), '_');
}
}
void Content::PostFunEmacsAdd()
@ -47,10 +30,11 @@ void Content::PostFunEmacsAdd()
request.item.privileges = 0644; // !! tymczasowo, bedzie uzyte umask
request.item.parent_id = request.dir_table.back()->id;
request.item.type = Item::file;
request.item.content_type = 1;// !! tymczasowo formatted text
// dates (creation and modification) is set by request.item.Clear() at the beginning
if( !request.HasWriteAccess(*request.dir_table.back() ) )
if( !request.CanUseEmacs(*request.dir_table.back() ) )
throw Error(Error::permision_denied);
request.session->done_status = db.AddItem(request.item);
@ -62,7 +46,7 @@ void Content::PostFunEmacsEdit(bool with_url)
{
request.session->done = Done::edited_item;
if( !request.HasWriteAccess(request.item) )
if( !request.CanUseEmacs(request.item) )
throw Error(Error::permision_denied);
time_t t = std::time(0);
@ -78,11 +62,30 @@ void Content::PostFunEmacsEdit(bool with_url)
void Content::PostFunEmacs()
{
bool adding = true;
if( request.is_item )
adding = false;
try
{
// these old values are ignored (if exists)
//!! tymczasowo, zabezpieczenie przed pustym url-em
try {
request.item.url = request.PostVar("url");
request.item.subject = request.PostVar("subject");
}
catch(...)
{
}
if( request.item.subject.empty() )
request.item.subject = request.dir_table.back()->subject;
// !! dodac skladanie tytuly z ostatniego katalogu i liczby okreslajacej ile jest elementow w srodku
// !! nie bedzie obciazany modul wyszukujacy bardzo
////////
request.item.content = request.PostVar("content");
bool with_url = false;
@ -92,10 +95,11 @@ void Content::PostFunEmacs()
PrepareUrl(request.item);
if( request.is_item )
PostFunEmacsEdit(with_url);
else
if( adding )
PostFunEmacsAdd();
else
PostFunEmacsEdit(with_url);
}
catch(const Error & e)
{
@ -106,9 +110,22 @@ void Content::PostFunEmacs()
if( request.session->done_status == Error::ok )
{
request.session->item = request.item;
request.session->done_timer = 2;
RedirectTo(request.item);
if( data.mounts.CurrentMountType() == Mount::thread )
{
if( adding )
db.EditThreadAddItem(request.dir_table.back()->id, request.item.id);
// request.session->item = request.item;
// request.session->done_timer = 2;
RedirectTo(*request.dir_table.back());
}
else
{
request.session->item = request.item;
request.session->done_timer = 2;
RedirectTo(request.item);
}
}
else
{
@ -128,14 +145,14 @@ void Content::FunEmacs()
if( !request.is_item )
{
// adding a new item
if( !request.HasReadWriteAccess(*request.dir_table.back()) )
if( !request.CanUseEmacs(*request.dir_table.back()) )
request.status = Error::permision_denied;
return;
}
// editing an existing item
if( !request.HasReadWriteAccess(request.item) )
if( !request.CanUseEmacs(request.item) )
{
request.status = Error::permision_denied;
return;

View File

@ -21,16 +21,9 @@ void Content::FunLs()
request.item_table.push_back( request.item );
return;
}
// !! a gdzie sprawdzenie uprawnien?
// we're showing the whole directory
Item item_ref;
item_ref.parent_id = request.dir_table.back()->id;
// !! zrobic inna metode, inny interfejs (jako parametr niech bierze parent_id), i zeby nie odczytywala contentu i subjectu (a moze tylko subject? przyda sie przy ls -l)
db.GetItems(request.item_table, item_ref);
// we're reading only files here
db.GetItems(request.item_table, request.dir_table.back()->id, Item::file, false, false, true);
}

View File

@ -16,9 +16,9 @@
void Content::PostFunMkdir(bool add_to_dir_table)
void Content::PostFunMkdir(bool add_to_dir_table, int mask)
{
if( !request.HasWriteAccess(*request.dir_table.back()) )
if( !request.CanUseMkdir(*request.dir_table.back()) )
{
request.status = Error::permision_denied;
return;
@ -30,12 +30,13 @@ void Content::PostFunMkdir(bool add_to_dir_table)
try
{
item.type = Item::dir;
item.subject = request.PostVar("subject");
item.url = request.PostVar("url");
item.parent_id = request.dir_table.back()->id;
item.user_id = request.session->puser ? request.session->puser->id : -1;
item.group_id = -1;
item.privileges = 0755; // !! tymczasowo, bedzie uzyte umask
item.default_item = -1; // !! tymczasowo, bedzie formularz z wprowadzeniem
item.privileges = mask;
item.default_item = -1;
// dates (creation and modification) is set by the Item() constructor
@ -72,7 +73,7 @@ void Content::PostFunMkdir(bool add_to_dir_table)
void Content::FunMkdir()
{
if( !request.HasWriteAccess(*request.dir_table.back()) )
if( !request.CanUseMkdir(*request.dir_table.back()) )
{
request.status = Error::permision_denied;
return;

View File

@ -14,76 +14,70 @@
#include "../core/data.h"
void Content::PostFunPriv()
void Content::PostFunPriv(Item & item)
{
// !! narazie tylko dla plikow
if( !request.is_item )
return;
try
{
long user_id = data.users.GetUserId( request.PostVar("user") );
long group_id = data.groups.GetGroupId( request.PostVar("group") );
int privileges = strtol( request.PostVar("privileges").c_str() , 0, 8);
if( !request.CanChangeUser(request.item, user_id) )
if( user_id==item.user_id && group_id==item.group_id && privileges==item.privileges )
{
log << log3 << "Content: PostFunPriv: nothing to change" << logend;
throw Error(Error::ok);
}
if( !request.CanChangeUser(item, user_id) )
throw Error(Error::cant_change_user);
if( !request.CanChangeGroup(request.item, group_id) )
if( !request.CanChangeGroup(item, group_id) )
throw Error(Error::cant_change_group);
if( !request.CanChangePrivileges(request.item, privileges) )
if( !request.CanChangePrivileges(item, privileges) )
throw Error(Error::cant_change_privileges);
request.item.user_id = user_id;
request.item.group_id = group_id;
request.item.privileges = privileges;
item.user_id = user_id;
item.group_id = group_id;
item.privileges = privileges;
request.session->done = Done::privileged_item;
request.session->done_status = db.EditPrivById(request.item, request.item.id);
request.session->done_status = db.EditPrivById(item, item.id);
}
catch(const Error & e)
{
log << log1 << "Content: FunChmod: Error: " << e << logend;
request.session->done_status = e;
}
if( request.session->done_status == Error::ok )
{
request.session->item = request.item;
request.session->done_timer = 2;
RedirectTo(request.item);
request.session->item = item;
request.session->done_timer = 2;
RedirectTo(item);
}
else
{
log << log1 << "Content: PostFunPrivileges: Error: " << static_cast<int>(request.session->done_status) << logend;
}
log << log1 << "Content: PostFunPriv: Error: " << static_cast<int>(request.session->done_status) << logend;
}
request.status = request.session->done_status;
}
void Content::PostFunPriv()
{
if( request.is_item )
PostFunPriv( request.item );
else
PostFunPriv( *request.dir_table.back() );
}
void Content::FunPriv()
{
if( !request.is_item )
{
// !! chwilowi tylko dla plikow
request.status == Error::item_required;
return;
}
// you must be an owner of the item (or a superuser)
// !! moze wykorzystac request.CanChangeUser() ?
if( !request.session->puser || (!request.session->puser->super_user && request.session->puser->id != request.item.user_id) )
{
request.status = Error::permision_denied;
return;
}
// we do not check permissions here
// permissions depends on the user, group, and privileges
}

View File

@ -53,33 +53,17 @@ void Content::FunRmDirRecursive()
void Content::FunRmDir()
{
if( request.dir_table.size() == 1 )
if( !request.CanRemove(*request.dir_table.back()) )
{
// rm for the root dir
// only the superuser can do it
if( !request.session->puser || !request.session->puser->super_user )
{
request.status = Error::permision_denied;
return;
}
request.status = Error::permision_denied;
return;
}
else
{
Item * last_but_one_dir = *(--(--request.dir_table.end()));
if( !request.HasWriteAccess(*last_but_one_dir) )
{
request.status = Error::permision_denied;
return;
}
}
if( request.param_table.empty() )
request.status = Error::permision_denied;
else
if( request.IsParam("confirm") )
return;
return;
else
if( request.IsParam("r") )
FunRmDirRecursive();
@ -96,7 +80,7 @@ void Content::FunRm()
return;
}
if( !request.HasWriteAccess(*request.dir_table.back()) )
if( !request.CanRemove(request.item) )
{
request.status = Error::permision_denied;
return;

View File

@ -13,24 +13,35 @@
#include "../core/data.h"
#include "../core/mount.h"
#include <algorithm>
bool Content::FunThreadSort(const Thread & t1, const Thread & t2)
{
Item * pdir1 = data.dirs.GetDir(t1.dir_id);
Item * pdir2 = data.dirs.GetDir(t2.dir_id);
if( !pdir1 || !pdir2 )
return false;
time_t time1 = mktime(&pdir1->date_creation);
time_t time2 = mktime(&pdir2->date_creation);
return time1 > time2;
}
void Content::FunThread()
{
// we're showing the whole directory
Item item_ref;
item_ref.parent_id = request.dir_table.back()->id;
// !! zrobic inna metode, inny interfejs (jako parametr niech bierze parent_id), i zeby nie odczytywala contentu i subjectu (a moze tylko subject? przyda sie przy ls -l)
bool asc = true;
Mount mount = data.mounts.GetCurrentMountPoint();
if( mount.IsParam(Mount::desc) )
if( data.mounts.CurrentMountIsParam(Mount::desc) )
asc = false;
db.GetItems(request.item_table, item_ref, asc);
db.GetItems(request.item_table, request.dir_table.back()->id, Item::file, true, true, asc);
db.GetThreads(request.dir_table.back()->id, request.thread_tab);
std::sort(request.thread_tab.begin(), request.thread_tab.end(), FunThreadSort);
}

View File

@ -30,12 +30,12 @@ lastcontainer.o: lastcontainer.h log.h
log.o: log.h
main.o: requestcontroller.h ../content/content.h ../core/item.h
main.o: ../templates/templates.h ../../ezc/src/ezc.h
main.o: ../templates/patterncacher.h ../app/templates.h sessionmanager.h
main.o: sessioncontainer.h session.h done.h item.h error.h log.h user.h
main.o: functionparser.h requesttypes.h ../app/content.h data.h dirs.h
main.o: dircontainer.h users.h ugcontainer.h groups.h group.h functions.h
main.o: function.h lastcontainer.h mounts.h mount.h request.h thread.h db.h
main.o: config.h ../confparser/confparser.h
main.o: ../templates/patterncacher.h ../app/templates.h ../core/thread.h
main.o: sessionmanager.h sessioncontainer.h session.h done.h item.h error.h
main.o: log.h user.h functionparser.h requesttypes.h ../app/content.h data.h
main.o: dirs.h dircontainer.h users.h ugcontainer.h groups.h group.h
main.o: functions.h function.h lastcontainer.h mounts.h mount.h request.h
main.o: thread.h db.h config.h ../confparser/confparser.h
misc.o: misc.h item.h log.h
mount.o: mount.h
mountparser.o: mountparser.h mount.h item.h error.h log.h data.h dirs.h
@ -47,17 +47,19 @@ mounts.o: lastcontainer.h request.h requesttypes.h session.h done.h error.h
mounts.o: thread.h mountparser.h
request.o: request.h requesttypes.h session.h done.h item.h error.h log.h
request.o: user.h function.h thread.h getparser.h httpsimpleparser.h
request.o: postparser.h cookieparser.h
request.o: postparser.h cookieparser.h data.h dirs.h dircontainer.h users.h
request.o: ugcontainer.h groups.h group.h functions.h lastcontainer.h
request.o: mounts.h mount.h
requestcontroller.o: requestcontroller.h ../content/content.h ../core/item.h
requestcontroller.o: ../templates/templates.h ../../ezc/src/ezc.h
requestcontroller.o: ../templates/patterncacher.h ../app/templates.h
requestcontroller.o: sessionmanager.h sessioncontainer.h session.h done.h
requestcontroller.o: item.h error.h log.h user.h functionparser.h
requestcontroller.o: requesttypes.h ../app/content.h data.h dirs.h
requestcontroller.o: dircontainer.h users.h ugcontainer.h groups.h group.h
requestcontroller.o: functions.h function.h lastcontainer.h mounts.h mount.h
requestcontroller.o: request.h thread.h postparser.h httpsimpleparser.h
requestcontroller.o: cookieparser.h
requestcontroller.o: ../core/thread.h sessionmanager.h sessioncontainer.h
requestcontroller.o: session.h done.h item.h error.h log.h user.h
requestcontroller.o: functionparser.h requesttypes.h ../app/content.h data.h
requestcontroller.o: dirs.h dircontainer.h users.h ugcontainer.h groups.h
requestcontroller.o: group.h functions.h function.h lastcontainer.h mounts.h
requestcontroller.o: mount.h request.h thread.h postparser.h
requestcontroller.o: httpsimpleparser.h cookieparser.h
session.o: session.h done.h item.h error.h log.h user.h
sessioncontainer.o: sessioncontainer.h session.h done.h item.h error.h log.h
sessioncontainer.o: user.h data.h dirs.h dircontainer.h users.h ugcontainer.h

View File

@ -361,6 +361,7 @@ void Db::CheckAllUrlSubject()
{
AssertConnection();
std::ostringstream query, query2;
// !! subject zostal wrzucony do tabeli item
query << "select item.id, subject from core.item left join core.content on item.content_id = content.id where url is null or url=''";
r = AssertQuery(query.str());
@ -419,16 +420,17 @@ Error Db::AddItemIntoItem(Item & item)
{
AssertConnection();
std::ostringstream query;
query << "insert into core.item (user_id, group_id, privileges, date_creation, date_modification, type, parent_id, content_id, default_item, url) values (";
query << '\'' << item.user_id << "', ";
query << '\'' << item.group_id << "', ";
query << '\'' << item.privileges << "', ";
query << '\'' << ConvertTime(item.date_creation) << "', ";
query << "insert into core.item (user_id, group_id, privileges, date_creation, date_modification, type, parent_id, content_id, default_item, subject, url) values (";
query << '\'' << item.user_id << "', ";
query << '\'' << item.group_id << "', ";
query << '\'' << item.privileges << "', ";
query << '\'' << ConvertTime(item.date_creation) << "', ";
query << '\'' << ConvertTime(item.date_modification) << "', ";
query << '\'' << static_cast<int>(item.type) << "', ";
query << '\'' << item.parent_id << "', ";
query << '\'' << item.content_id << "', ";
query << '\'' << item.default_item << "', ";
query << '\'' << static_cast<int>(item.type) << "', ";
query << '\'' << item.parent_id << "', ";
query << '\'' << item.content_id << "', ";
query << '\'' << item.default_item << "', ";
query << '\'' << Escape(item.subject) << "', ";
url_without_id = AddItemCreateUrlSubject(item);
@ -468,10 +470,9 @@ Error Db::AddItemIntoContent(Item & item)
{
AssertConnection();
std::ostringstream query;
query << "insert into core.content (subject, content, content_type) values (";
query << '\'' << Escape(item.subject) << "', ";
query << '\'' << Escape(item.content) << "', ";
query << '\'' << item.content_type << "');";
query << "insert into core.content (content, content_type) values (";
query << '\'' << Escape(item.content) << "', ";
query << '\'' << item.content_type << "');";
r = AssertQuery(query.str());
AssertResultStatus(r, PGRES_COMMAND_OK);
@ -511,8 +512,7 @@ return result;
// !! with_subject zamienic na with_url
Error Db::EditItemInItem(Item & item, bool with_subject)
Error Db::EditItemInItem(Item & item, bool with_url)
{
PGresult * r = 0;
Error result = Error::ok;
@ -522,22 +522,23 @@ Error Db::EditItemInItem(Item & item, bool with_subject)
{
AssertConnection();
std::ostringstream query;
query << "update core.item set (user_id, group_id, privileges, date_creation, date_modification, type, default_item, parent_id";
query << "update core.item set (user_id, group_id, privileges, date_creation, date_modification, type, default_item, parent_id, subject";
if( with_subject )
if( with_url )
query << ", url";
query << ") = (";
query << '\'' << item.user_id << "', ";
query << '\'' << item.group_id << "', ";
query << '\'' << item.privileges << "', ";
query << '\'' << ConvertTime(item.date_creation) << "', ";
query << '\'' << item.user_id << "', ";
query << '\'' << item.group_id << "', ";
query << '\'' << item.privileges << "', ";
query << '\'' << ConvertTime(item.date_creation) << "', ";
query << '\'' << ConvertTime(item.date_modification) << "', ";
query << '\'' << static_cast<int>(item.type) << "', ";
query << '\'' << item.default_item << "', ";
query << '\'' << item.parent_id << "' ";
query << '\'' << static_cast<int>(item.type) << "', ";
query << '\'' << item.default_item << "', ";
query << '\'' << item.parent_id << "', ";
query << '\'' << Escape(item.subject) << "' ";
if( with_subject )
if( with_url )
{
url_without_id = AddItemCreateUrlSubject(item);
@ -552,7 +553,7 @@ Error Db::EditItemInItem(Item & item, bool with_subject)
r = AssertQuery(query.str());
AssertResultStatus(r, PGRES_COMMAND_OK);
if( with_subject && !url_without_id )
if( with_url && !url_without_id )
ToString(item.url, item.id);
}
catch(const Error & e)
@ -576,9 +577,8 @@ Error Db::EditItemInContent(Item & item)
{
AssertConnection();
std::ostringstream query;
query << "update core.content set (subject, content, content_type) = (";
query << "update core.content set (content, content_type) = (";
query << '\'' << Escape(item.subject) << "', ";
query << '\'' << Escape(item.content) << "', ";
query << '\'' << item.content_type << "' ";
@ -664,9 +664,8 @@ return result;
// item.id must be set
// !! with_subject zamienic na with_url
// !! moze nazwa poprostu EditItem (nie trzeba tego ById) ? (sprawdzic czy nie koliduje z inna nazwa)
Error Db::EditItemById(Item & item, bool with_subject)
Error Db::EditItemById(Item & item, bool with_url)
{
Error result = Error::ok;
@ -681,7 +680,7 @@ Error Db::EditItemById(Item & item, bool with_subject)
result = EditItemInContent(item);
if( result == Error::ok )
result = EditItemInItem(item, with_subject);
result = EditItemInItem(item, with_url);
}
return result;
@ -691,7 +690,7 @@ return result;
// item.url and item.parent_id must be set
// doesn't work with directiories
Error Db::EditItemByUrl(Item & item, bool with_subject)
Error Db::EditItemByUrl(Item & item, bool with_url)
{
Error result = EditItemGetId(item);
@ -700,7 +699,7 @@ Error Db::EditItemByUrl(Item & item, bool with_subject)
result = EditItemInContent(item);
if( result == Error::ok )
result = EditItemInItem(item, with_subject);
result = EditItemInItem(item, with_url);
}
return result;
@ -747,33 +746,48 @@ return result;
PGresult * Db::GetItemsQuery(Item & item_ref, bool asc)
PGresult * Db::GetItemsQuery(long parent_id, Item::Type type, bool with_subject, bool with_content, bool sort_asc)
{
std::ostringstream query;
query << "select * from core.item left join core.content on item.content_id = content.id where type!='0' and parent_id='" << item_ref.parent_id << "'";
query << "select item.id, user_id, group_id, privileges, date_creation, date_modification, url, type, parent_id, content_id, default_item";
if( item_ref.id != -1 )
query << " and item.id='" << item_ref.id << "'";
if( type != Item::dir )
{
if( with_subject )
query << ", subject";
if( with_content )
query << ", content, content_type";
}
if( !item_ref.url.empty() )
query << " and url='" << Escape(item_ref.url) << "'";
query << " from core.item";
if( type != Item::dir && with_content )
query << " left join core.content on item.content_id = content.id";
query << " where parent_id='" << parent_id << "'";
query << " order by item.date_modification";
if( type == Item::dir )
query << " and type='0'";
if( type == Item::file )
query << " and type='1'";
if( asc )
query << " order by item.date_creation";
if( sort_asc )
query << " asc";
else
query << " desc";
query << ';';
return AssertQuery(query.str());
}
void Db::GetItems(std::vector<Item> & item_table, Item & item_ref, bool asc)
void Db::GetItems(std::vector<Item> & item_table, long parent_id, Item::Type type, bool with_subject, bool with_content, bool sort_asc)
{
item_table.clear();
PGresult * r = 0;
@ -782,7 +796,7 @@ void Db::GetItems(std::vector<Item> & item_table, Item & item_ref, bool asc)
{
AssertConnection();
r = GetItemsQuery(item_ref, asc);
r = GetItemsQuery(parent_id, type, with_subject, with_content, sort_asc);
AssertResultStatus(r, PGRES_TUPLES_OK);
Item item;
@ -930,7 +944,8 @@ long Db::GetDirId(long parent_id, const std::string & url)
// !! w tej metodzie odczytujemy tylko uprawnienia?
// bo w tej chwili jest caly item odczytywany
bool Db::GetPriv(Item & item, long id)
{
bool result = false;
@ -1380,7 +1395,7 @@ Error Db::GetThreadByDirId(long dir_id, Thread & thread)
AssertConnection();
std::ostringstream query;
query << "select id, dir_id, subject, closed from core.thread where thread.dir_id = " << dir_id << ";";
query << "select thread.id, thread.parent_id, thread.dir_id, thread.closed, thread.items, thread.last_item, item.date_modification, item.user_id from core.thread left join core.item on thread.last_item = item.id where thread.dir_id = '" << dir_id << "';";
r = AssertQuery( query.str() );
AssertResultStatus(r, PGRES_TUPLES_OK);
@ -1391,20 +1406,81 @@ Error Db::GetThreadByDirId(long dir_id, Thread & thread)
log << log1 << "Db: there is more than one thread with dir_id: " << dir_id << logend;
else
if( rows == 0 )
{
log << log1 << "Db: there is no a thread with dir_id: " << dir_id << logend;
throw Error(Error::no_thread);
}
int cid = AssertColumn(r, "id");
int cdir_id = AssertColumn(r, "dir_id");
int csubject = AssertColumn(r, "subject");
int cclosed = AssertColumn(r, "closed");
int cid = AssertColumn(r, "id");
int cparent_id = AssertColumn(r, "parent_id");
int cdir_id = AssertColumn(r, "dir_id");
int cclosed = AssertColumn(r, "closed");
int citems = AssertColumn(r, "items");
int clast_item = AssertColumn(r, "last_item");
int cdate_modification = PQfnumber(r, "date_modification");
int cuser_id = PQfnumber(r, "user_id");
thread.id = atol( AssertValue(r, 0, cid) );
thread.parent_id = atol( AssertValue(r, 0, cparent_id) );
thread.dir_id = atol( AssertValue(r, 0, cdir_id) );
thread.closed = atol( AssertValue(r, 0, cclosed) ) == 0 ? false : true;
thread.items = atol( AssertValue(r, 0, citems) );
thread.last_item.id = atol( AssertValue(r, 0, clast_item) );
thread.last_item.date_modification = ConvertTime( Db::AssertValue(r, 0, cdate_modification) );
thread.last_item.user_id = atol( Db::AssertValue(r, 0, cuser_id) );
}
catch(const Error & e)
{
status = e;
}
ClearResult(r);
thread.id = atol( AssertValue(r, 0, cid) );
thread.dir_id = atol( AssertValue(r, 0, cdir_id) );
thread.subject = AssertValue(r, 0, csubject);
thread.closed = atol( AssertValue(r, 0, cclosed) ) == 0 ? false : true;
return status;
}
Error Db::GetThreads(long parent_id, std::vector<Thread> & thread_tab)
{
PGresult * r = 0;
Error status = Error::ok;
try
{
AssertConnection();
std::ostringstream query;
query << "select thread.id, thread.parent_id, thread.dir_id, thread.closed, thread.items, thread.last_item, item.date_modification, item.user_id "
"from core.thread left join core.item on thread.last_item = item.id "
"where thread.parent_id = '" << parent_id << "' order by date_modification asc;";
r = AssertQuery( query.str() );
AssertResultStatus(r, PGRES_TUPLES_OK);
int rows = PQntuples(r);
Thread thread;
int cid = AssertColumn(r, "id");
int cparent_id = AssertColumn(r, "parent_id");
int cdir_id = AssertColumn(r, "dir_id");
int cclosed = AssertColumn(r, "closed");
int citems = AssertColumn(r, "items");
int clast_item = AssertColumn(r, "last_item");
int cdate_modification = PQfnumber(r, "date_modification");
int cuser_id = PQfnumber(r, "user_id");
for(int i=0 ; i<rows ; ++i)
{
thread.id = atol( AssertValue(r, i, cid) );
thread.parent_id = atol( AssertValue(r, i, cparent_id) );
thread.dir_id = atol( AssertValue(r, i, cdir_id) );
thread.closed = atol( AssertValue(r, i, cclosed) ) == 0 ? false : true;
thread.items = atol( AssertValue(r, i, citems) );
thread.last_item.id = atol( AssertValue(r, i, clast_item) );
thread.last_item.date_modification = ConvertTime( Db::AssertValue(r, i, cdate_modification) );
thread.last_item.user_id = atol( Db::AssertValue(r, i, cuser_id) );
thread_tab.push_back(thread);
}
}
catch(const Error & e)
{
@ -1420,6 +1496,7 @@ return status;
Error Db::AddThread(Thread & thread)
{
PGresult * r = 0;
@ -1429,10 +1506,12 @@ Error Db::AddThread(Thread & thread)
{
AssertConnection();
std::ostringstream query;
query << "insert into core.thread (dir_id, subject, closed) values (";
query << "insert into core.thread (parent_id, dir_id, closed, items, last_item) values (";
query << '\'' << thread.parent_id << "', ";
query << '\'' << thread.dir_id << "', ";
query << '\'' << Escape(thread.subject) << "', ";
query << '\'' << (thread.closed ? 1 : 0 ) << "'); ";
query << '\'' << (thread.closed ? 1 : 0 ) << "', ";
query << '\'' << thread.items << "', ";
query << '\'' << thread.last_item.id << "'); ";
r = AssertQuery(query.str());
AssertResultStatus(r, PGRES_COMMAND_OK);
@ -1451,3 +1530,27 @@ return status;
}
Error Db::EditThreadAddItem(long dir_id, long item_id)
{
PGresult * r = 0;
Error status = Error::ok;
try
{
AssertConnection();
std::ostringstream query;
query << "update core.thread set (last_item, items) = ('" << item_id << "', items+1) where dir_id='" << dir_id << "';";
r = AssertQuery(query.str());
AssertResultStatus(r, PGRES_COMMAND_OK);
}
catch(const Error & e)
{
status = e;
}
ClearResult(r);
return status;
}

View File

@ -45,11 +45,15 @@ public:
void Init(const std::string & database, const std::string & user, const std::string & pass);
bool CheckUser(std::string & login, std::string & password, long & user_id);
Error AddItem(Item & item);
Error EditItemById(Item & item, bool with_subject = true);
Error EditItemByUrl(Item & item, bool with_subject = true);
Error EditItemById(Item & item, bool with_url = true);
Error EditItemByUrl(Item & item, bool with_url = true);
void CheckAllUrlSubject();
void GetItems(std::vector<Item> & item_table, Item & item_ref, bool asc = true);
void GetItems(std::vector<Item> & item_table, long parent_id, Item::Type type, bool with_subject, bool with_content, bool sort_asc);
void GetItem(std::vector<Item> & item_table, long id);
bool GetPriv(Item & item, long id);
Error EditPrivById(Item & item, long id);
@ -78,7 +82,9 @@ public:
Error AddThread(Thread & thread);
Error GetThreadByDirId(long dir_id, Thread & thread);
Error GetThreads(long parent_id, std::vector<Thread> & thread_tab);
Error EditThreadAddItem(long dir_id, long item_id);
protected:
PGconn * pg_conn;
@ -103,14 +109,14 @@ protected:
Error AddItemIntoContent(Item & item);
Error AddItemIntoItem(Item & item);
Error EditItemInItem(Item & item, bool with_subject);
Error EditItemInItem(Item & item, bool with_url);
Error EditItemInContent(Item & item);