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:
161
core/request.cpp
161
core/request.cpp
@@ -12,7 +12,7 @@
|
||||
#include "postparser.h"
|
||||
#include "cookieparser.h"
|
||||
#include "log.h"
|
||||
|
||||
#include "data.h"
|
||||
|
||||
|
||||
Request::Request() : char_empty(0)
|
||||
@@ -66,7 +66,10 @@ void Request::Clear()
|
||||
|
||||
status = Error::ok;
|
||||
|
||||
is_thread = false;
|
||||
thread.Clear();
|
||||
|
||||
thread_tab.clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -491,4 +494,160 @@ bool Request::HasReadExecAccess(const Item & item)
|
||||
}
|
||||
|
||||
|
||||
// returning true if we can create a thread in the current directory
|
||||
bool Request::CanCreateThread(bool check_root)
|
||||
{
|
||||
if( request.dir_table.empty() )
|
||||
return false;
|
||||
|
||||
if( request.is_item )
|
||||
return false;
|
||||
|
||||
if( !HasWriteAccess(*request.dir_table.back()) )
|
||||
return false;
|
||||
|
||||
if( data.mounts.CurrentMountType() != Mount::thread )
|
||||
return false;
|
||||
|
||||
if( !check_root && session && session->puser && session->puser->super_user )
|
||||
// super can create thread regardless of the restrictcreatethread option
|
||||
return true;
|
||||
|
||||
|
||||
// !! w przyszlosci mozna odczytywac wiecej parametrow od restrictcreatethread
|
||||
// tymczasowo wykorzystujemy tylko pierwszy
|
||||
int level;
|
||||
if( data.mounts.CurrentMountIsParam(Mount::restrictcreatethread, &level) )
|
||||
{
|
||||
if( level == -1 )
|
||||
return false;
|
||||
|
||||
// we can only allow on a specific level
|
||||
if( int(request.dir_table.size()) != level )
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Request::CanRemove(const Item & item)
|
||||
{
|
||||
if( item.parent_id == -1 )
|
||||
{
|
||||
// rm for the root dir
|
||||
// only the superuser can do it
|
||||
if( !request.session->puser || !request.session->puser->super_user )
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Item * last_but_one_dir = data.dirs.GetDir(item.parent_id);
|
||||
|
||||
if( !last_but_one_dir )
|
||||
// ops, there is no a parent dir
|
||||
return false;
|
||||
|
||||
if( !request.HasWriteAccess(*last_but_one_dir) )
|
||||
return false;
|
||||
}
|
||||
|
||||
if( data.mounts.CurrentMountIsParam(Mount::only_root_can_remove) )
|
||||
// this can be deleted only be a root
|
||||
if( !request.session->puser || !request.session->puser->super_user )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Request::CanUseEmacs(const Item & item, bool check_root)
|
||||
{
|
||||
if( !check_root && request.session->puser && request.session->puser->super_user )
|
||||
// super user can use emacs everywhere
|
||||
return true;
|
||||
|
||||
if( !request.HasWriteAccess(item) )
|
||||
return false;
|
||||
|
||||
int level;
|
||||
if( data.mounts.CurrentMountIsParam(Mount::can_use_emacs_on, &level) )
|
||||
if( level != int(request.dir_table.size()) )
|
||||
return false;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Request::CanUseMkdir(const Item & item, bool check_root)
|
||||
{
|
||||
// you can create a directory only in a directory
|
||||
if( item.type != Item::dir )
|
||||
return false;
|
||||
|
||||
if( !check_root && request.session->puser && request.session->puser->super_user )
|
||||
// super user can use mkdir everywhere
|
||||
return true;
|
||||
|
||||
if( !request.HasWriteAccess(item) )
|
||||
return false;
|
||||
|
||||
int level;
|
||||
if( data.mounts.CurrentMountIsParam(Mount::can_use_mkdir_on, &level) )
|
||||
if( level != int(request.dir_table.size()) )
|
||||
return false;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Request::CanUseHtml(long user_id)
|
||||
{
|
||||
User * puser = data.users.GetUser(user_id);
|
||||
|
||||
if( !puser )
|
||||
return false;
|
||||
|
||||
if( puser->super_user )
|
||||
// super user can use html
|
||||
return true;
|
||||
|
||||
long group = data.groups.GetGroupId("allow_html");
|
||||
|
||||
if( group == -1 )
|
||||
// there is no such a group
|
||||
return false;
|
||||
|
||||
if( puser->IsMemberOf(group) )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool Request::CanUseBBCode(long user_id)
|
||||
{
|
||||
User * puser = data.users.GetUser(user_id);
|
||||
|
||||
if( !puser )
|
||||
return false;
|
||||
|
||||
if( puser->super_user )
|
||||
// super user can use bbcode
|
||||
return true;
|
||||
|
||||
long group = data.groups.GetGroupId("allow_bbcode");
|
||||
|
||||
if( group == -1 )
|
||||
// there is no such a group
|
||||
return false;
|
||||
|
||||
if( puser->IsMemberOf(group) )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user