some ezc functions from templates/item.cpp moved to Item and ItemContent
methods HasAccess() HasReadAccess() and similar moved from System to Item and ItemContent
This commit is contained in:
@@ -37,6 +37,8 @@
|
||||
#include "finder.h"
|
||||
#include "core/request.h"
|
||||
#include "templates/templates.h"
|
||||
#include "core/session.h"
|
||||
|
||||
|
||||
|
||||
namespace Winix
|
||||
@@ -58,21 +60,32 @@ void Item::fields()
|
||||
|
||||
int type_helper = static_cast<int>(type);
|
||||
|
||||
field(L"id", id, morm::FT::no_insertable | morm::FT::no_updatable | morm::FT::primary_key);
|
||||
field(L"parent_id", parent_id);
|
||||
field(L"type", type_helper);
|
||||
field(L"url", url);
|
||||
field(L"subject", subject);
|
||||
field(L"template", html_template);
|
||||
field(L"sort_index", sort_index);
|
||||
field(L"id", id, morm::FT::no_insertable | morm::FT::no_updatable | morm::FT::primary_key);
|
||||
field(L"parent_id", parent_id);
|
||||
field(L"type", type_helper);
|
||||
field(L"url", url);
|
||||
field(L"subject", subject);
|
||||
field(L"template", html_template);
|
||||
field(L"sort_index", sort_index);
|
||||
field(L"content_id", L"content", item_content, morm::FT::foreign_key);
|
||||
|
||||
field(L"is", &Item::is);
|
||||
field(L"dir_link", &Item::dir_link);
|
||||
field(L"link", &Item::link);
|
||||
field(L"dir_link", &Item::dir_link);
|
||||
field(L"link", &Item::link);
|
||||
field(L"is_parent_for_current_dir", &Item::is_parent_for_current_dir);
|
||||
field(L"is_current_dir", &Item::is_current_dir);
|
||||
field(L"is_root", &Item::is_root);
|
||||
field(L"is_current_dir", &Item::is_current_dir);
|
||||
field(L"is_root_dir", &Item::is_root_dir);
|
||||
|
||||
field(L"type_is_symlink", &Item::type_is_symlink);
|
||||
field(L"type_is_file", &Item::type_is_file);
|
||||
field(L"type_is_dir", &Item::type_is_dir);
|
||||
field(L"type_is_none", &Item::type_is_none);
|
||||
|
||||
field(L"url_is", &Item::url_is);
|
||||
|
||||
field(L"can_be_removed", &Item::can_be_removed);
|
||||
field(L"has_read_access", &Item::has_read_access);
|
||||
field(L"has_write_access", &Item::has_write_access);
|
||||
|
||||
|
||||
|
||||
// may we should add a method setTypeFromInt(int t)?
|
||||
@@ -156,8 +169,6 @@ bool Item::update(morm::ModelData * model_data, bool update_whole_tree)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Item::Clear()
|
||||
{
|
||||
id = -1;
|
||||
@@ -171,199 +182,6 @@ void Item::Clear()
|
||||
}
|
||||
|
||||
|
||||
CalcItemsHelper Item::calc_items_by_url(long parent_id, const std::wstring & url)
|
||||
{
|
||||
morm::Finder<CalcItemsHelper> finder(model_connector);
|
||||
|
||||
CalcItemsHelper helper = finder.
|
||||
prepare_to_select().
|
||||
raw("select count(id) as size, min(id) as item_id from core.item").
|
||||
where().
|
||||
eq(L"parent_id", parent_id).
|
||||
eq(L"url", url).
|
||||
get();
|
||||
|
||||
return helper;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* may we should check for '.' and '..' here too?
|
||||
*/
|
||||
bool Item::prepare_url()
|
||||
{
|
||||
std::wstring temp_url;
|
||||
bool is_that_url;
|
||||
const int max_index = 99;
|
||||
size_t index = 1;
|
||||
std::wstring postfix;
|
||||
|
||||
// only root dir may not have the url
|
||||
if( parent_id != -1 && url.empty() )
|
||||
url = L"_";
|
||||
|
||||
do
|
||||
{
|
||||
if( index > 1 )
|
||||
{
|
||||
postfix = L"_(";
|
||||
pt::Toa(index, postfix, false);
|
||||
postfix += L")";
|
||||
}
|
||||
|
||||
PrepareNewFileName(url, postfix, temp_url);
|
||||
|
||||
CalcItemsHelper helper = calc_items_by_url(parent_id, temp_url);
|
||||
|
||||
if( helper.size > 0 )
|
||||
{
|
||||
is_that_url = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
url = temp_url;
|
||||
is_that_url = false;
|
||||
}
|
||||
|
||||
index += 1;
|
||||
}
|
||||
while( is_that_url && index <= max_index );
|
||||
|
||||
return !is_that_url;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Item::propagate_connector()
|
||||
{
|
||||
item_content.set_connector(model_connector);
|
||||
}
|
||||
|
||||
|
||||
// IMPROVEME move me to a better place
|
||||
void Item::print_dir(Ezc::FunInfo<HtmlTextStream> & env)
|
||||
{
|
||||
Request * req = get_request();
|
||||
|
||||
if( req )
|
||||
{
|
||||
for(size_t a=0 ; a < req->dir_tab.size() ; ++a)
|
||||
env.out << req->dir_tab[a]->url << '/';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// IMPROVEME move me to a better place
|
||||
void Item::print_dir_without_slash(Ezc::FunInfo<HtmlTextStream> & env)
|
||||
{
|
||||
Request * req = get_request();
|
||||
|
||||
if( req )
|
||||
{
|
||||
for(size_t a=0 ; a < req->dir_tab.size() ; ++a)
|
||||
{
|
||||
env.out << req->dir_tab[a]->url;
|
||||
|
||||
if( a < req->dir_tab.size()-1 )
|
||||
env.out << '/';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Item::is(Ezc::FunInfo<HtmlTextStream> & env)
|
||||
{
|
||||
Request * req = get_request();
|
||||
|
||||
if( req )
|
||||
{
|
||||
env.res = req->is_item;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Item::dir_link(Ezc::FunInfo<HtmlTextStream> & env)
|
||||
{
|
||||
Dirs * dirs = get_dirs();
|
||||
std::vector<Item*> dir_tab;
|
||||
|
||||
if( dirs && dirs->CreateDirTab(parent_id, dir_tab) )
|
||||
{
|
||||
for(Item * pitem : dir_tab)
|
||||
{
|
||||
env.out << pitem->url << '/';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Item::link(Ezc::FunInfo<HtmlTextStream> & env)
|
||||
{
|
||||
Config * config = get_config();
|
||||
Request * req = get_request();
|
||||
|
||||
if( config && req )
|
||||
{
|
||||
TemplatesFunctions::doc_proto(env);
|
||||
|
||||
if( !req->subdomain.empty() )
|
||||
env.out << req->subdomain << '.';
|
||||
|
||||
env.out << config->base_url;
|
||||
|
||||
if( parent_id == req->dir_tab.back()->id )
|
||||
{
|
||||
print_dir(env);
|
||||
}
|
||||
else
|
||||
{
|
||||
dir_link(env);
|
||||
}
|
||||
|
||||
env.out << url;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Item::is_parent_for_current_dir(Ezc::FunInfo<HtmlTextStream> & env)
|
||||
{
|
||||
Request * req = get_request();
|
||||
|
||||
if( req )
|
||||
{
|
||||
if( req->dir_tab.size() > 1 )
|
||||
{
|
||||
env.res = (id == req->dir_tab[req->dir_tab.size() - 2]->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Item::is_current_dir(Ezc::FunInfo<HtmlTextStream> & env)
|
||||
{
|
||||
Request * req = get_request();
|
||||
|
||||
if( req )
|
||||
{
|
||||
env.res = (id == req->dir_tab.back()->id);
|
||||
}
|
||||
}
|
||||
|
||||
// rename to is_root_dir
|
||||
void Item::is_root(Ezc::FunInfo<HtmlTextStream> & env)
|
||||
{
|
||||
Request * req = get_request();
|
||||
|
||||
if( req )
|
||||
{
|
||||
// add a test whether this is a directory (not a file or a symlink)
|
||||
env.res = (parent_id == -1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -499,5 +317,295 @@ bool Item::do_migration_to_4()
|
||||
|
||||
|
||||
|
||||
bool Item::can_remove_child(const User * current_user, long child_user_id) const
|
||||
{
|
||||
bool res = false;
|
||||
|
||||
if( type == Type::dir )
|
||||
{
|
||||
if( current_user && current_user->super_user )
|
||||
{
|
||||
res = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
res = item_content.has_write_access(current_user);
|
||||
|
||||
if( res && item_content.is_sticky_bit_set() )
|
||||
{
|
||||
// IMPROVEME what about if child_user_id is -1 (guest)
|
||||
res = (item_content.user_id == child_user_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
bool Item::can_be_removed(const User * current_user) const
|
||||
{
|
||||
bool res = false;
|
||||
const Dirs * dirs = get_dirs();
|
||||
|
||||
if( dirs && parent_id != -1 )
|
||||
{
|
||||
const Item * parent_dir = dirs->GetDir(parent_id);
|
||||
|
||||
if( parent_dir )
|
||||
{
|
||||
res = parent_dir->can_remove_child(current_user, id);
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
bool Item::can_remove_child(long child_user_id) const
|
||||
{
|
||||
return can_remove_child(get_current_user(), child_user_id);
|
||||
}
|
||||
|
||||
|
||||
bool Item::can_be_removed() const
|
||||
{
|
||||
return can_be_removed(get_current_user());
|
||||
}
|
||||
|
||||
|
||||
bool Item::has_read_access()
|
||||
{
|
||||
return item_content.has_read_access();
|
||||
}
|
||||
|
||||
|
||||
bool Item::has_write_access()
|
||||
{
|
||||
return item_content.has_write_access();
|
||||
}
|
||||
|
||||
|
||||
bool Item::type_is_symlink() const
|
||||
{
|
||||
return (type == Type::symlink);
|
||||
}
|
||||
|
||||
|
||||
bool Item::type_is_file() const
|
||||
{
|
||||
return (type == Type::file);
|
||||
}
|
||||
|
||||
|
||||
bool Item::type_is_dir() const
|
||||
{
|
||||
return (type == Type::dir);
|
||||
}
|
||||
|
||||
|
||||
bool Item::type_is_none() const
|
||||
{
|
||||
return (type == Type::none);
|
||||
}
|
||||
|
||||
|
||||
bool Item::is_root_dir() const
|
||||
{
|
||||
return (type == Type::dir && parent_id == -1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
CalcItemsHelper Item::calc_items_by_url(long parent_id, const std::wstring & url)
|
||||
{
|
||||
morm::Finder<CalcItemsHelper> finder(model_connector);
|
||||
|
||||
CalcItemsHelper helper = finder.
|
||||
prepare_to_select().
|
||||
raw("select count(id) as size, min(id) as item_id from core.item").
|
||||
where().
|
||||
eq(L"parent_id", parent_id).
|
||||
eq(L"url", url).
|
||||
get();
|
||||
|
||||
return helper;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* may we should check for '.' and '..' here too?
|
||||
*/
|
||||
bool Item::prepare_url()
|
||||
{
|
||||
std::wstring temp_url;
|
||||
bool is_that_url;
|
||||
const int max_index = 99;
|
||||
size_t index = 1;
|
||||
std::wstring postfix;
|
||||
|
||||
// only root dir may not have the url
|
||||
if( parent_id != -1 && url.empty() )
|
||||
url = L"_";
|
||||
|
||||
do
|
||||
{
|
||||
if( index > 1 )
|
||||
{
|
||||
postfix = L"_(";
|
||||
pt::Toa(index, postfix, false);
|
||||
postfix += L")";
|
||||
}
|
||||
|
||||
PrepareNewFileName(url, postfix, temp_url);
|
||||
|
||||
CalcItemsHelper helper = calc_items_by_url(parent_id, temp_url);
|
||||
|
||||
if( helper.size > 0 )
|
||||
{
|
||||
is_that_url = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
url = temp_url;
|
||||
is_that_url = false;
|
||||
}
|
||||
|
||||
index += 1;
|
||||
}
|
||||
while( is_that_url && index <= max_index );
|
||||
|
||||
return !is_that_url;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Item::propagate_connector()
|
||||
{
|
||||
item_content.set_connector(model_connector);
|
||||
}
|
||||
|
||||
|
||||
// IMPROVEME move me to a better place
|
||||
void Item::print_dir(EzcEnv & env)
|
||||
{
|
||||
Request * req = get_request();
|
||||
|
||||
if( req )
|
||||
{
|
||||
for(size_t a=0 ; a < req->dir_tab.size() ; ++a)
|
||||
env.out << req->dir_tab[a]->url << '/';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// IMPROVEME move me to a better place
|
||||
void Item::print_dir_without_slash(EzcEnv & env)
|
||||
{
|
||||
Request * req = get_request();
|
||||
|
||||
if( req )
|
||||
{
|
||||
for(size_t a=0 ; a < req->dir_tab.size() ; ++a)
|
||||
{
|
||||
env.out << req->dir_tab[a]->url;
|
||||
|
||||
if( a < req->dir_tab.size()-1 )
|
||||
env.out << '/';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Item::dir_link(EzcEnv & env)
|
||||
{
|
||||
Dirs * dirs = get_dirs();
|
||||
std::vector<Item*> dir_tab;
|
||||
|
||||
if( dirs && dirs->CreateDirTab(parent_id, dir_tab) )
|
||||
{
|
||||
for(Item * pitem : dir_tab)
|
||||
{
|
||||
env.out << pitem->url << '/';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Item::link(EzcEnv & env)
|
||||
{
|
||||
Config * config = get_config();
|
||||
Request * req = get_request();
|
||||
|
||||
if( config && req )
|
||||
{
|
||||
TemplatesFunctions::doc_proto(env);
|
||||
|
||||
if( !req->subdomain.empty() )
|
||||
env.out << req->subdomain << '.';
|
||||
|
||||
env.out << config->base_url;
|
||||
|
||||
if( parent_id == req->dir_tab.back()->id )
|
||||
{
|
||||
print_dir(env);
|
||||
}
|
||||
else
|
||||
{
|
||||
dir_link(env);
|
||||
}
|
||||
|
||||
env.out << url;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Item::is_parent_for_current_dir() const
|
||||
{
|
||||
bool res = false;
|
||||
const Request * req = get_request();
|
||||
|
||||
if( req )
|
||||
{
|
||||
if( req->dir_tab.size() > 1 )
|
||||
{
|
||||
res = (id == req->dir_tab[req->dir_tab.size() - 2]->id);
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
bool Item::is_current_dir() const
|
||||
{
|
||||
bool res = false;
|
||||
const Request * req = get_request();
|
||||
|
||||
if( req )
|
||||
{
|
||||
res = (id == req->dir_tab.back()->id);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Item::url_is(EzcEnv & env)
|
||||
{
|
||||
env.res = (url == env.par);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
|
||||
#include "funinfo.h"
|
||||
#include "templates/htmltextstream.h"
|
||||
#include "templates/misc.h"
|
||||
|
||||
|
||||
|
||||
@@ -183,16 +184,23 @@ public:
|
||||
|
||||
void propagate_connector();
|
||||
|
||||
bool can_remove_child(const User * current_user, long child_user_id) const;
|
||||
bool can_be_removed(const User * current_user) const;
|
||||
bool can_remove_child(long child_user_id) const;
|
||||
bool can_be_removed() const;
|
||||
|
||||
void print_dir(Ezc::FunInfo<HtmlTextStream> & env);
|
||||
void print_dir_without_slash(Ezc::FunInfo<HtmlTextStream> & env);
|
||||
bool has_read_access();
|
||||
bool has_write_access();
|
||||
|
||||
bool type_is_symlink() const;
|
||||
bool type_is_file() const;
|
||||
bool type_is_dir() const;
|
||||
bool type_is_none() const;
|
||||
|
||||
bool is_root_dir() const;
|
||||
bool is_parent_for_current_dir() const;
|
||||
bool is_current_dir() const;
|
||||
|
||||
void is(Ezc::FunInfo<HtmlTextStream> & env);
|
||||
void dir_link(Ezc::FunInfo<HtmlTextStream> & env);
|
||||
void link(Ezc::FunInfo<HtmlTextStream> & env);
|
||||
void is_parent_for_current_dir(Ezc::FunInfo<HtmlTextStream> & env);
|
||||
void is_current_dir(Ezc::FunInfo<HtmlTextStream> & env);
|
||||
void is_root(Ezc::FunInfo<HtmlTextStream> & env);
|
||||
|
||||
|
||||
protected:
|
||||
@@ -204,7 +212,17 @@ protected:
|
||||
bool do_migration_to_3();
|
||||
bool do_migration_to_4();
|
||||
|
||||
void print_dir(EzcEnv & env);
|
||||
void print_dir_without_slash(EzcEnv & env);
|
||||
void dir_link(EzcEnv & env);
|
||||
void link(EzcEnv & env);
|
||||
|
||||
void url_is(EzcEnv & env);
|
||||
|
||||
|
||||
|
||||
MORM_MEMBER_FIELD(Item)
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -37,6 +37,9 @@
|
||||
#include "core/misc.h"
|
||||
#include "templates/misc.h"
|
||||
#include "core/bbcodeparser.h"
|
||||
#include "core/request.h"
|
||||
#include "core/users.h"
|
||||
#include "core/groups.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
@@ -83,7 +86,23 @@ void ItemContent::fields()
|
||||
field(L"meta_admin", meta_admin);
|
||||
|
||||
field(L"print_content", &ItemContent::print_content);
|
||||
field(L"has_static_file", &ItemContent::has_static_file);
|
||||
field(L"privileges_octal", &ItemContent::privileges_octal);
|
||||
field(L"user_name", &ItemContent::user_name);
|
||||
field(L"group_name", &ItemContent::group_name);
|
||||
field(L"type_is", &ItemContent::type_is);
|
||||
field(L"is_empty", &ItemContent::is_empty);
|
||||
|
||||
field(L"file_type_is_none", &ItemContent::file_type_is_none);
|
||||
field(L"file_type_is_image", &ItemContent::file_type_is_image);
|
||||
field(L"file_type_is_video", &ItemContent::file_type_is_video);
|
||||
field(L"file_type_is_sound", &ItemContent::file_type_is_sound);
|
||||
|
||||
field(L"has_thumb", &ItemContent::has_thumb);
|
||||
|
||||
|
||||
|
||||
// IMPROVEME prepare a setter functions which tests whether content_raw_type_helper and content_parsed_type_helper are correct values
|
||||
content_raw_type = static_cast<ContentType>(content_raw_type_helper);
|
||||
content_parsed_type = static_cast<ContentType>(content_parsed_type_helper);
|
||||
}
|
||||
@@ -153,66 +172,6 @@ void ItemContent::Clear()
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* we're using the HtmlFilter only for those contents
|
||||
*
|
||||
*/
|
||||
bool ItemContent::CanContentBeHtmlFiltered(ItemContent::ContentType ct)
|
||||
{
|
||||
return ct == ct_text || ct == ct_formatted_text || ct == ct_html || ct == ct_bbcode;
|
||||
}
|
||||
|
||||
bool ItemContent::CanContentBeHtmlFiltered()
|
||||
{
|
||||
return CanContentBeHtmlFiltered(content_raw_type);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void ItemContent::print_content(HtmlTextStream & out, const std::wstring & content, ItemContent::ContentType content_type, bool is_html_filter_on)
|
||||
{
|
||||
using TemplatesFunctions::R;
|
||||
|
||||
if( is_html_filter_on && !ItemContent::CanContentBeHtmlFiltered(content_type) )
|
||||
out << R("<nofilter>");
|
||||
|
||||
if( content_type == ItemContent::ct_text )
|
||||
{
|
||||
out << content;
|
||||
}
|
||||
else
|
||||
if( content_type == ItemContent::ct_formatted_text )
|
||||
{
|
||||
TemplatesFunctions::HtmlEscapeFormTxt(out, content);
|
||||
}
|
||||
else
|
||||
if( content_type == ItemContent::ct_bbcode )
|
||||
{
|
||||
static std::wstring out_temp;
|
||||
out_temp.clear();
|
||||
out_temp.reserve(content.size()*2);
|
||||
|
||||
BBCODEParser bbcode_parser; // IMPROVE ME move me to a better place
|
||||
bbcode_parser.Filter(content.c_str(), out_temp);
|
||||
out << R(out_temp);
|
||||
}
|
||||
else
|
||||
{
|
||||
// ct_html, ct_other
|
||||
out << R(content);
|
||||
}
|
||||
|
||||
if( is_html_filter_on && !ItemContent::CanContentBeHtmlFiltered(content_type) )
|
||||
out << R("</nofilter>");
|
||||
}
|
||||
|
||||
|
||||
void ItemContent::print_content(Ezc::FunInfo<HtmlTextStream> & env)
|
||||
{
|
||||
print_content(env.out, content_raw, content_raw_type, true); // IMPROVE ME get the 'true' from the config (config->html_filter)
|
||||
}
|
||||
|
||||
|
||||
bool ItemContent::do_migration(int & current_table_version)
|
||||
{
|
||||
@@ -305,6 +264,268 @@ bool ItemContent::do_migration_to_3()
|
||||
}
|
||||
|
||||
|
||||
bool ItemContent::has_access(const User * current_user, int mask) const
|
||||
{
|
||||
if( current_user )
|
||||
{
|
||||
if( current_user->super_user )
|
||||
{
|
||||
// super user is allowed everything
|
||||
return true;
|
||||
}
|
||||
|
||||
if( user_id != -1 && current_user->id == user_id )
|
||||
{
|
||||
// the owner
|
||||
return ((privileges >> 9) & mask) == mask;
|
||||
}
|
||||
|
||||
if( group_id != -1 && current_user->IsMemberOf(group_id) )
|
||||
{
|
||||
// group
|
||||
return ((privileges >> 6) & mask) == mask;
|
||||
}
|
||||
|
||||
// others -- others logged users
|
||||
return ((privileges >> 3) & mask) == mask;
|
||||
}
|
||||
|
||||
// guests -- not logged users
|
||||
return (privileges & mask) == mask;
|
||||
}
|
||||
|
||||
|
||||
bool ItemContent::has_read_access(const User * current_user) const
|
||||
{
|
||||
return has_access(current_user, 4); // r
|
||||
}
|
||||
|
||||
|
||||
bool ItemContent::has_write_access(const User * current_user) const
|
||||
{
|
||||
return has_access(current_user, 2); // w
|
||||
}
|
||||
|
||||
|
||||
bool ItemContent::has_read_write_access(const User * current_user) const
|
||||
{
|
||||
return has_access(current_user, 6); // r+w
|
||||
}
|
||||
|
||||
|
||||
bool ItemContent::has_read_exec_access(const User * current_user) const
|
||||
{
|
||||
if( current_user && current_user->super_user )
|
||||
{
|
||||
// there must be at least one 'x' (for the root)
|
||||
// !! CHECK ME: is it applicable to directories too?
|
||||
return (privileges & 01111) != 0;
|
||||
}
|
||||
|
||||
return has_access(current_user, 5); // r+x
|
||||
}
|
||||
|
||||
|
||||
bool ItemContent::has_read_access() const
|
||||
{
|
||||
return has_read_access(get_current_user());
|
||||
}
|
||||
|
||||
|
||||
bool ItemContent::has_write_access() const
|
||||
{
|
||||
return has_write_access(get_current_user());
|
||||
}
|
||||
|
||||
|
||||
bool ItemContent::has_read_write_access() const
|
||||
{
|
||||
return has_read_write_access(get_current_user());
|
||||
}
|
||||
|
||||
|
||||
bool ItemContent::has_read_exec_access() const
|
||||
{
|
||||
return has_read_exec_access(get_current_user());
|
||||
}
|
||||
|
||||
|
||||
bool ItemContent::is_sticky_bit_set() const
|
||||
{
|
||||
int mask = 010000;
|
||||
return (privileges & mask) == mask;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* we're using the HtmlFilter only for those contents
|
||||
*
|
||||
*/
|
||||
bool ItemContent::CanContentBeHtmlFiltered(ItemContent::ContentType ct)
|
||||
{
|
||||
return ct == ct_text || ct == ct_formatted_text || ct == ct_html || ct == ct_bbcode;
|
||||
}
|
||||
|
||||
bool ItemContent::CanContentBeHtmlFiltered()
|
||||
{
|
||||
return CanContentBeHtmlFiltered(content_raw_type);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void ItemContent::print_content(HtmlTextStream & out, const std::wstring & content, ItemContent::ContentType content_type, bool is_html_filter_on)
|
||||
{
|
||||
using TemplatesFunctions::R;
|
||||
|
||||
if( is_html_filter_on && !ItemContent::CanContentBeHtmlFiltered(content_type) )
|
||||
out << R("<nofilter>");
|
||||
|
||||
if( content_type == ItemContent::ct_text )
|
||||
{
|
||||
out << content;
|
||||
}
|
||||
else
|
||||
if( content_type == ItemContent::ct_formatted_text )
|
||||
{
|
||||
TemplatesFunctions::HtmlEscapeFormTxt(out, content);
|
||||
}
|
||||
else
|
||||
if( content_type == ItemContent::ct_bbcode )
|
||||
{
|
||||
static std::wstring out_temp;
|
||||
out_temp.clear();
|
||||
out_temp.reserve(content.size()*2);
|
||||
|
||||
BBCODEParser bbcode_parser; // IMPROVE ME move me to a better place
|
||||
bbcode_parser.Filter(content.c_str(), out_temp);
|
||||
out << R(out_temp);
|
||||
}
|
||||
else
|
||||
{
|
||||
// ct_html, ct_other
|
||||
out << R(content);
|
||||
}
|
||||
|
||||
if( is_html_filter_on && !ItemContent::CanContentBeHtmlFiltered(content_type) )
|
||||
out << R("</nofilter>");
|
||||
}
|
||||
|
||||
|
||||
void ItemContent::print_content(EzcEnv & env)
|
||||
{
|
||||
print_content(env.out, content_raw, content_raw_type, true); // IMPROVE ME get the 'true' from the config (config->html_filter)
|
||||
}
|
||||
|
||||
|
||||
void ItemContent::has_static_file(EzcEnv & env)
|
||||
{
|
||||
env.res = file_type != WINIX_ITEM_FILETYPE_NONE && !file_path.empty();
|
||||
}
|
||||
|
||||
|
||||
void ItemContent::privileges_octal(EzcEnv & env)
|
||||
{
|
||||
env.out << Toa(privileges, 8);
|
||||
}
|
||||
|
||||
|
||||
void ItemContent::user_name(EzcEnv & env)
|
||||
{
|
||||
Users * users = get_users();
|
||||
|
||||
if( users )
|
||||
{
|
||||
User * puser = users->GetUser(user_id);
|
||||
TemplatesFunctions::print_user_name(env, puser, guest_name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ItemContent::group_name(EzcEnv & env)
|
||||
{
|
||||
Groups * groups = get_groups();
|
||||
|
||||
if( groups )
|
||||
{
|
||||
Group * pgroup = groups->GetGroup(group_id);
|
||||
|
||||
if( pgroup )
|
||||
env.out << pgroup->name;
|
||||
else
|
||||
env.out << group_id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ItemContent::type_is(EzcEnv & env)
|
||||
{
|
||||
if( content_raw_type == ItemContent::ct_text && env.par == L"text" )
|
||||
env.res = true;
|
||||
else
|
||||
if( content_raw_type == ItemContent::ct_formatted_text && env.par == L"formatted text" )
|
||||
env.res = true;
|
||||
else
|
||||
if( content_raw_type == ItemContent::ct_html && env.par == L"html" )
|
||||
env.res = true;
|
||||
else
|
||||
if( content_raw_type == ItemContent::ct_bbcode && env.par == L"bbcode" )
|
||||
env.res = true;
|
||||
else
|
||||
if( content_raw_type == ItemContent::ct_other && env.par == L"other" )
|
||||
env.res = true;
|
||||
}
|
||||
|
||||
|
||||
void ItemContent::is_empty(EzcEnv & env)
|
||||
{
|
||||
env.res = content_raw.empty();
|
||||
}
|
||||
|
||||
|
||||
void ItemContent::file_type_is_none(EzcEnv & env)
|
||||
{
|
||||
env.res = file_type == WINIX_ITEM_FILETYPE_NONE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* when we change file_type to string the we can return true only for
|
||||
* those images which can be able to show by a webbrowser
|
||||
*
|
||||
*/
|
||||
void ItemContent::file_type_is_image(EzcEnv & env)
|
||||
{
|
||||
env.res = file_type == WINIX_ITEM_FILETYPE_IMAGE;
|
||||
}
|
||||
|
||||
/*
|
||||
* similar we can return true only for those videos which can be rendered by a webbrowser
|
||||
*/
|
||||
void ItemContent::file_type_is_video(EzcEnv & env)
|
||||
{
|
||||
env.res = file_type == WINIX_ITEM_FILETYPE_VIDEO;
|
||||
}
|
||||
|
||||
|
||||
void ItemContent::file_type_is_sound(EzcEnv & env)
|
||||
{
|
||||
//env.res = file_type == WINIX_ITEM_FILETYPE_;
|
||||
env.res = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ItemContent::has_thumb(EzcEnv & env)
|
||||
{
|
||||
env.res = file_has_thumb;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
||||
@@ -36,10 +36,12 @@
|
||||
#define headerfile_winix_models_itemcontent
|
||||
|
||||
#include <string>
|
||||
#include "winixmodel.h"
|
||||
#include "space/space.h"
|
||||
#include "date/date.h"
|
||||
#include "model.h"
|
||||
#include "templates/htmltextstream.h"
|
||||
#include "templates/misc.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
@@ -55,10 +57,33 @@ namespace Winix
|
||||
|
||||
|
||||
|
||||
class ItemContent : public morm::Model
|
||||
class ItemContent : public WinixModel
|
||||
{
|
||||
public:
|
||||
|
||||
/*
|
||||
* IMPROVEME
|
||||
*
|
||||
* the kind of content type would be better to be a string
|
||||
* so instead of 'ContentType content_raw_type' we would have 'std::wstring content_raw_type'
|
||||
* this allows us to use plugin system to define its own types such as markdown
|
||||
*
|
||||
* if we show an editor (such as emacs) then we call plugins with a specified message
|
||||
* and each plugin will put a string if it provides a content type mechanism
|
||||
* (we can have pt::Space as a parameter in plugins - this can be a table of strings)
|
||||
*
|
||||
* after user clicks 'save' button we send another message with content_raw and content_raw_type
|
||||
* and we expect content_raw_parsed to be made by a plugin
|
||||
*
|
||||
* or we have two content_type strings, one for internal use and the other for locale files (to show to a user)
|
||||
* or even three, the last one used as a description
|
||||
*
|
||||
*
|
||||
*
|
||||
* file_type should be a string, we can use libmagick library to get the correct type
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* may we should add ct_none? and this will be default (set in Clear method)
|
||||
*/
|
||||
@@ -124,7 +149,7 @@ public:
|
||||
|
||||
|
||||
/*
|
||||
* name of a link in the case when type is a symlink or a directory
|
||||
* name of a link in the case whct_texten type is a symlink or a directory
|
||||
*/
|
||||
std::wstring link_to;
|
||||
|
||||
@@ -226,16 +251,24 @@ public:
|
||||
* what about clear() from Model?
|
||||
*/
|
||||
void Clear();
|
||||
|
||||
static bool CanContentBeHtmlFiltered(ItemContent::ContentType ct);
|
||||
bool CanContentBeHtmlFiltered();
|
||||
|
||||
|
||||
static void print_content(HtmlTextStream & out, const std::wstring & content, ItemContent::ContentType content_type, bool is_html_filter_on);
|
||||
void print_content(Ezc::FunInfo<HtmlTextStream> & env);
|
||||
|
||||
bool do_migration(int & current_table_version);
|
||||
|
||||
static bool CanContentBeHtmlFiltered(ItemContent::ContentType ct);
|
||||
static void print_content(HtmlTextStream & out, const std::wstring & content, ItemContent::ContentType content_type, bool is_html_filter_on);
|
||||
|
||||
bool CanContentBeHtmlFiltered();
|
||||
|
||||
bool has_read_access(const User * current_user) const;
|
||||
bool has_write_access(const User * current_user) const;
|
||||
bool has_read_write_access(const User * current_user) const;
|
||||
bool has_read_exec_access(const User * current_user) const;
|
||||
|
||||
bool has_read_access() const;
|
||||
bool has_write_access() const;
|
||||
bool has_read_write_access() const;
|
||||
bool has_read_exec_access() const;
|
||||
|
||||
bool is_sticky_bit_set() const;
|
||||
|
||||
|
||||
protected:
|
||||
@@ -244,6 +277,22 @@ protected:
|
||||
bool do_migration_to_2();
|
||||
bool do_migration_to_3();
|
||||
|
||||
bool has_access(const User * current_user, int mask) const;
|
||||
|
||||
void print_content(EzcEnv & env);
|
||||
void has_static_file(EzcEnv & env);
|
||||
void privileges_octal(EzcEnv & env);
|
||||
void user_name(EzcEnv & env);
|
||||
void group_name(EzcEnv & env);
|
||||
void type_is(EzcEnv & env);
|
||||
void is_empty(EzcEnv & env);
|
||||
void file_type_is_none(EzcEnv & env);
|
||||
void file_type_is_image(EzcEnv & env);
|
||||
void file_type_is_video(EzcEnv & env);
|
||||
void file_type_is_sound(EzcEnv & env);
|
||||
void has_thumb(EzcEnv & env);
|
||||
|
||||
|
||||
MORM_MEMBER_FIELD(ItemContent)
|
||||
|
||||
};
|
||||
|
||||
@@ -125,11 +125,11 @@ void User::clear_passwords()
|
||||
|
||||
|
||||
|
||||
bool User::IsMemberOf(long group)
|
||||
bool User::IsMemberOf(long group) const
|
||||
{
|
||||
std::vector<long>::iterator i;
|
||||
std::vector<long>::const_iterator i;
|
||||
|
||||
for(i=groups.begin() ; i!=groups.end() ; ++i)
|
||||
for(i=groups.cbegin() ; i!=groups.cend() ; ++i)
|
||||
if( *i == group )
|
||||
return true;
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@ public:
|
||||
void after_select();
|
||||
|
||||
void Clear(); // IMPROVEME what about clear() from Model?
|
||||
bool IsMemberOf(long group);
|
||||
bool IsMemberOf(long group) const;
|
||||
bool ReadMonthDayTime(pt::Date & date, const wchar_t * str);
|
||||
bool SetTzFromEnv();
|
||||
|
||||
|
||||
@@ -33,6 +33,9 @@
|
||||
*/
|
||||
|
||||
#include "winixmodel.h"
|
||||
#include "core/session.h"
|
||||
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
@@ -141,6 +144,162 @@ SLog * WinixModel::get_session_logger()
|
||||
}
|
||||
|
||||
|
||||
Session * WinixModel::get_session()
|
||||
{
|
||||
WinixModelConnector * connector = get_winix_model_connector();
|
||||
|
||||
if( connector )
|
||||
{
|
||||
return connector->get_winix_session();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
User * WinixModel::get_current_user()
|
||||
{
|
||||
Session * session = get_session();
|
||||
|
||||
if( session )
|
||||
{
|
||||
return session->puser;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const Config * WinixModel::get_config() const
|
||||
{
|
||||
const WinixModelConnector * connector = get_winix_model_connector();
|
||||
|
||||
if( connector )
|
||||
{
|
||||
return connector->get_winix_config();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
const Request * WinixModel::get_request() const
|
||||
{
|
||||
const WinixModelConnector * connector = get_winix_model_connector();
|
||||
|
||||
if( connector )
|
||||
{
|
||||
return connector->get_winix_request();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
const Log * WinixModel::get_logger() const
|
||||
{
|
||||
const WinixModelConnector * connector = get_winix_model_connector();
|
||||
|
||||
if( connector )
|
||||
{
|
||||
return connector->get_winix_logger();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
const Dirs * WinixModel::get_dirs() const
|
||||
{
|
||||
const WinixModelConnector * connector = get_winix_model_connector();
|
||||
|
||||
if( connector )
|
||||
{
|
||||
return connector->get_winix_dirs();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
const Mounts * WinixModel::get_mounts() const
|
||||
{
|
||||
const WinixModelConnector * connector = get_winix_model_connector();
|
||||
|
||||
if( connector )
|
||||
{
|
||||
return connector->get_winix_mounts();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
const Users * WinixModel::get_users() const
|
||||
{
|
||||
const WinixModelConnector * connector = get_winix_model_connector();
|
||||
|
||||
if( connector )
|
||||
{
|
||||
return connector->get_winix_users();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
const Groups * WinixModel::get_groups() const
|
||||
{
|
||||
const WinixModelConnector * connector = get_winix_model_connector();
|
||||
|
||||
if( connector )
|
||||
{
|
||||
return connector->get_winix_groups();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
const SLog * WinixModel::get_session_logger() const
|
||||
{
|
||||
const WinixModelConnector * connector = get_winix_model_connector();
|
||||
|
||||
if( connector )
|
||||
{
|
||||
return connector->get_winix_session_logger();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
const Session * WinixModel::get_session() const
|
||||
{
|
||||
const WinixModelConnector * connector = get_winix_model_connector();
|
||||
|
||||
if( connector )
|
||||
{
|
||||
return connector->get_winix_session();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const User * WinixModel::get_current_user() const
|
||||
{
|
||||
const Session * session = get_session();
|
||||
|
||||
if( session )
|
||||
{
|
||||
return session->puser;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -155,6 +314,16 @@ WinixModelConnector * WinixModel::get_winix_model_connector()
|
||||
}
|
||||
|
||||
|
||||
const WinixModelConnector * WinixModel::get_winix_model_connector() const
|
||||
{
|
||||
if( model_connector )
|
||||
{
|
||||
return dynamic_cast<const WinixModelConnector*>(model_connector);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -50,6 +50,9 @@ class Mounts;
|
||||
class Users;
|
||||
class Groups;
|
||||
class SLog;
|
||||
class Session;
|
||||
class User;
|
||||
|
||||
|
||||
|
||||
class WinixModel : public morm::Model
|
||||
@@ -64,10 +67,24 @@ public:
|
||||
Users * get_users();
|
||||
Groups * get_groups();
|
||||
SLog * get_session_logger(); // FIXME always return null at the moment, should be set when a new request is created and clear at the end of a request
|
||||
Session * get_session();
|
||||
User * get_current_user();
|
||||
|
||||
const Config * get_config() const;
|
||||
const Request * get_request() const;
|
||||
const Log * get_logger() const; // there is no need for logger to be const, we can do nothing with such a logger
|
||||
const Dirs * get_dirs() const;
|
||||
const Mounts * get_mounts() const;
|
||||
const Users * get_users() const;
|
||||
const Groups * get_groups() const;
|
||||
const SLog * get_session_logger() const; // FIXME always return null at the moment, should be set when a new request is created and clear at the end of a request
|
||||
const Session * get_session() const;
|
||||
const User * get_current_user() const;
|
||||
|
||||
protected:
|
||||
|
||||
WinixModelConnector * get_winix_model_connector();
|
||||
const WinixModelConnector * get_winix_model_connector() const;
|
||||
|
||||
|
||||
};
|
||||
|
||||
@@ -49,6 +49,7 @@ WinixModelConnector::WinixModelConnector()
|
||||
users = nullptr;
|
||||
groups = nullptr;
|
||||
slog = nullptr;
|
||||
session = nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -93,12 +94,74 @@ Groups * WinixModelConnector::get_winix_groups()
|
||||
return groups;
|
||||
}
|
||||
|
||||
|
||||
SLog * WinixModelConnector::get_winix_session_logger()
|
||||
{
|
||||
return slog;
|
||||
}
|
||||
|
||||
|
||||
Session * WinixModelConnector::get_winix_session()
|
||||
{
|
||||
return session;
|
||||
}
|
||||
|
||||
|
||||
const Config * WinixModelConnector::get_winix_config() const
|
||||
{
|
||||
return config;
|
||||
}
|
||||
|
||||
|
||||
const Request * WinixModelConnector::get_winix_request() const
|
||||
{
|
||||
return request;
|
||||
}
|
||||
|
||||
|
||||
const Log * WinixModelConnector::get_winix_logger() const
|
||||
{
|
||||
return log;
|
||||
}
|
||||
|
||||
|
||||
const Dirs * WinixModelConnector::get_winix_dirs() const
|
||||
{
|
||||
return dirs;
|
||||
}
|
||||
|
||||
|
||||
const Mounts * WinixModelConnector::get_winix_mounts() const
|
||||
{
|
||||
return mounts;
|
||||
}
|
||||
|
||||
|
||||
const Users * WinixModelConnector::get_winix_users() const
|
||||
{
|
||||
return users;
|
||||
}
|
||||
|
||||
|
||||
const Groups * WinixModelConnector::get_winix_groups() const
|
||||
{
|
||||
return groups;
|
||||
}
|
||||
|
||||
|
||||
const SLog * WinixModelConnector::get_winix_session_logger() const
|
||||
{
|
||||
return slog;
|
||||
}
|
||||
|
||||
|
||||
const Session * WinixModelConnector::get_winix_session() const
|
||||
{
|
||||
return session;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void WinixModelConnector::set_winix_config(Config * config)
|
||||
{
|
||||
this->config = config;
|
||||
@@ -140,11 +203,18 @@ void WinixModelConnector::set_winix_groups(Groups * groups)
|
||||
this->groups = groups;
|
||||
}
|
||||
|
||||
|
||||
void WinixModelConnector::set_winix_session_logger(SLog * slog)
|
||||
{
|
||||
this->slog = slog;
|
||||
}
|
||||
|
||||
|
||||
void WinixModelConnector::set_winix_session(Session * session)
|
||||
{
|
||||
this->session = session;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ class Mounts;
|
||||
class Users;
|
||||
class Groups;
|
||||
class SLog;
|
||||
class Session;
|
||||
|
||||
|
||||
class WinixModelConnector : public morm::ModelConnector
|
||||
@@ -64,6 +65,17 @@ public:
|
||||
Users * get_winix_users();
|
||||
Groups * get_winix_groups();
|
||||
SLog * get_winix_session_logger();
|
||||
Session * get_winix_session();
|
||||
|
||||
const Config * get_winix_config() const;
|
||||
const Request * get_winix_request() const;
|
||||
const Log * get_winix_logger() const;
|
||||
const Dirs * get_winix_dirs() const;
|
||||
const Mounts * get_winix_mounts() const;
|
||||
const Users * get_winix_users() const;
|
||||
const Groups * get_winix_groups() const;
|
||||
const SLog * get_winix_session_logger() const;
|
||||
const Session * get_winix_session() const;
|
||||
|
||||
void set_winix_config(Config * config);
|
||||
void set_winix_request(Request * request);
|
||||
@@ -73,6 +85,7 @@ public:
|
||||
void set_winix_users(Users * users);
|
||||
void set_winix_groups(Groups * groups);
|
||||
void set_winix_session_logger(SLog * slog);
|
||||
void set_winix_session(Session * session);
|
||||
|
||||
|
||||
protected:
|
||||
@@ -85,6 +98,7 @@ protected:
|
||||
Users * users;
|
||||
Groups * groups;
|
||||
SLog * slog;
|
||||
Session * session;
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user