ItemContent::user_name(EzcEnv & env) changed to ItemContent::user(morm::ModelWrapper ** model_wrapper) and we return a User class

ItemContent::group_name(EzcEnv & env) changed to ItemContent::group(morm::ModelWrapper ** model_wrapper) and we return a Group class
added ItemContent::display_user_name(EzcEnv & env)
some functions in templates/item.cpp moved to Item
master
Tomasz Sowa 2 years ago
parent d8c1a81bcb
commit e7c7324058

@ -341,6 +341,9 @@ bool App::Init()
model_connector.set_winix_groups(&system.groups);
model_connector.set_winix_session_logger(nullptr); // will be set for each request
model_connector.set_winix_session(nullptr); // will be set for each request
model_connector.set_winix_locale(&TemplatesFunctions::locale);
model_connector.set_winix_session_manager(&session_manager);
model_connector.set_winix_time_zones(&system.time_zones);
if( !TryToMakeDatabaseMigration() )
return false;

@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2011-2019, Tomasz Sowa
* Copyright (c) 2011-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -105,11 +105,9 @@ void ThreadManager::Add(BaseThread * pbase, const wchar_t * thread_name)
data.model_connector.set_winix_groups(nullptr);
data.model_connector.set_winix_session_logger(nullptr);
data.model_connector.set_winix_session(nullptr);
//data.model_connector.set_winix_request();
data.model_connector.set_winix_locale(nullptr); // null for a moment, may will be changed
data.model_connector.set_winix_session_manager(nullptr);// null for a moment, may will be changed
data.model_connector.set_winix_time_zones(nullptr);// null for a moment, may will be changed
item.object->set_model_connector(&data.model_connector);

@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2011-2014, Tomasz Sowa
* Copyright (c) 2011-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

@ -1,20 +1,20 @@
[if item_content_type_is "other"][item.content.print_content][else]
[if item.content.type_is "other"][item.content.print_content][else]
[if false]
[if mount_page_arg_is "subject"][if mount_page_arg_is "info"]<h1 class="withinfo">[else]<h1>[end][item_subject]</h1>[end]
[if mount_page_arg_is "info"][include "item_info.html"][end]
[if mount_page_arg_is "subject"][if mount_page_arg_is "info"]<h1 class="withinfo">[else]<h1>[end][item.subject]</h1>[end]
[if mount_page_arg_is "info"][include "item.info.html"][end]
[end]
[if one item_filetype_is_image]
[if item.content.file_type_is_image]
<a href="[item_link]"><img class="catimage" [if not item_has_thumb]height="100"[end] src="[item_link]/download[if item_has_thumb]/thumb[end]" alt="[item_subject]"></a>
<a href="[item.link]"><img class="catimage" [if not item.has_thumb]height="100"[end] src="[item.link]/download[if item.has_thumb]/thumb[end]" alt="[item.subject]"></a>
[# we use pre.nowinixbreak to tell the html_filter not to put a blank space into those urles]
<div>
<pre class="nowinixbreak">
{cat_image_url}: [item_link]<br>
{cat_image_thumb_url}: [item_link]/-/thumb
{cat_image_url}: [item.link]<br>
{cat_image_thumb_url}: [item.link]/-/thumb
</pre>
</div>
@ -22,11 +22,11 @@
[else]
[if not item_filetype_is_none]
{download}: <a href="[item_link]/download" title="[item_subject]">[item_subject]</a>
[if not item.content.file_type_is_none]
{download}: <a href="[item.link]/download" title="[item.subject]">[item.subject]</a>
<div>
<pre class="nowinixbreak">
{cat_file_url}: [item_link]<br>
{cat_file_url}: [item.link]<br>
</pre>
</div>

@ -10,6 +10,7 @@ winix_frontend_tooltip = Visit UIkit 3 site
logged_as = logged as
not_existing_user = not existing user
display_guest_name = guest
unknown = unknown

@ -10,6 +10,7 @@ winix_frontend_tooltip = Odwiedź stronę UIkit 3
logged_as = zalogowany jako
not_existing_user = brak takiego użytkownika
display_guest_name = gość
unknown = nie znany

@ -597,14 +597,17 @@ bool Item::is_current_dir() const
}
void Item::url_is(EzcEnv & env)
{
env.res = (url == env.par);
}
//bool Item::has_read_accessxx() const
//{
//
//}
} // namespace Winix

@ -88,8 +88,8 @@ void ItemContent::fields()
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"user", &ItemContent::user);
field(L"group", &ItemContent::group);
field(L"type_is", &ItemContent::type_is);
field(L"is_empty", &ItemContent::is_empty);
@ -99,6 +99,7 @@ void ItemContent::fields()
field(L"file_type_is_sound", &ItemContent::file_type_is_sound);
field(L"has_thumb", &ItemContent::has_thumb);
field(L"display_user_name", &ItemContent::display_user_name);
@ -432,19 +433,23 @@ void ItemContent::privileges_octal(EzcEnv & env)
}
void ItemContent::user_name(EzcEnv & env)
void ItemContent::user(morm::ModelWrapper ** model_wrapper)
{
Users * users = get_users();
if( users )
{
User * puser = users->GetUser(user_id);
TemplatesFunctions::print_user_name(env, puser, guest_name);
if( puser )
{
*model_wrapper = new morm::ModelWrapperModel(puser);
}
}
}
void ItemContent::group_name(EzcEnv & env)
void ItemContent::group(morm::ModelWrapper ** model_wrapper)
{
Groups * groups = get_groups();
@ -453,9 +458,9 @@ void ItemContent::group_name(EzcEnv & env)
Group * pgroup = groups->GetGroup(group_id);
if( pgroup )
env.out << pgroup->name;
else
env.out << group_id;
{
*model_wrapper = new morm::ModelWrapperModel(pgroup);
}
}
}
@ -525,6 +530,50 @@ void ItemContent::has_thumb(EzcEnv & env)
}
void ItemContent::display_user_name(EzcEnv & env)
{
Locale * locale = get_locale();
if( user_id != -1 )
{
Users * users = get_users();
if( users )
{
User * user = users->GetUser(user_id);
if( user )
{
user->display_name(env);
}
else
{
if( locale )
locale->Get(L"not_existing_user");
else
env.out << "not existing user";
}
}
}
else
{
// IMPROVEME these should be moved to a better place
env.out << "~";
if( !guest_name.empty() && !IsWhite(guest_name) )
{
env.out << guest_name;
}
else
{
if( locale )
env.out << locale->Get(L"display_guest_name");
else
env.out << "guest";
}
}
}
} // namespace Winix

@ -282,8 +282,8 @@ protected:
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 user(morm::ModelWrapper ** model_wrapper);
void group(morm::ModelWrapper ** model_wrapper);
void type_is(EzcEnv & env);
void is_empty(EzcEnv & env);
void file_type_is_none(EzcEnv & env);
@ -291,6 +291,7 @@ protected:
void file_type_is_video(EzcEnv & env);
void file_type_is_sound(EzcEnv & env);
void has_thumb(EzcEnv & env);
void display_user_name(EzcEnv & env);
MORM_MEMBER_FIELD(ItemContent)

@ -34,6 +34,7 @@
#include "user.h"
#include "core/misc.h"
#include "templates/templates.h"
namespace Winix
@ -51,23 +52,23 @@ User::User()
void User::fields()
{
field(L"id", id, morm::FT::no_insertable | morm::FT::no_updatable | morm::FT::primary_key);
field(L"login", name); // IMPROVEME set the same name, either 'login' or 'name'
field(L"super_user", super_user);
field(L"has_pass", has_pass);
field(L"pass_type", pass_type);
field(L"password", password);
field(L"pass_encrypted", pass_encrypted, morm::FT::binary);
field(L"pass_hash_salted", pass_hash_salted);
field(L"email", email);
field(L"notify", notify);
field(L"env", env);
field(L"aenv", aenv);
field(L"status", status);
field(L"locale_id", locale_id);
field(L"time_zone_id", time_zone_id);
field(L"id", id, morm::FT::no_insertable | morm::FT::no_updatable | morm::FT::primary_key);
field(L"login", name); // IMPROVEME set the same name, either 'login' or 'name'
field(L"super_user", super_user); // IMPROVEME rename to is_super_user
field(L"has_pass", has_pass);
field(L"pass_type", pass_type);
field(L"password", L"", password);
field(L"pass_encrypted", L"", pass_encrypted, morm::FT::binary);
field(L"pass_hash_salted", pass_hash_salted); // IMPROVEME rename to pass_is_hash_salted or is_pass_hash_salted
field(L"email", email);
field(L"notify", notify);
field(L"env", env);
field(L"aenv", aenv); // IMPROVEME rename to admin_env
field(L"status", status);
field(L"locale_id", locale_id);
field(L"time_zone_id", time_zone_id);
}
@ -177,6 +178,15 @@ bool User::do_migration_to_1()
void User::display_name(EzcEnv & env)
{
std::wstring * dname = aenv.get_wstr(L"display_name");
if( dname && !IsWhite(*dname, true) )
env.out << *dname;
else
env.out << name;
}

@ -40,6 +40,7 @@
#include "model.h"
#include "space/space.h"
#include "date/date.h"
#include "templates/misc.h"
namespace Winix
@ -145,6 +146,8 @@ public:
bool do_migration(int & current_table_version);
void display_name(EzcEnv & env);
private:

@ -170,6 +170,47 @@ User * WinixModel::get_current_user()
}
Locale * WinixModel::get_locale()
{
WinixModelConnector * connector = get_winix_model_connector();
if( connector )
{
return connector->get_winix_locale();
}
return nullptr;
}
SessionManager * WinixModel::get_session_manager()
{
WinixModelConnector * connector = get_winix_model_connector();
if( connector )
{
return connector->get_winix_session_manager();
}
return nullptr;
}
TimeZones * WinixModel::get_time_zones()
{
WinixModelConnector * connector = get_winix_model_connector();
if( connector )
{
return connector->get_winix_time_zones();
}
return nullptr;
}
const Config * WinixModel::get_config() const
{
@ -303,6 +344,50 @@ const User * WinixModel::get_current_user() const
const Locale * WinixModel::get_locale() const
{
const WinixModelConnector * connector = get_winix_model_connector();
if( connector )
{
return connector->get_winix_locale();
}
return nullptr;
}
const SessionManager * WinixModel::get_session_manager() const
{
const WinixModelConnector * connector = get_winix_model_connector();
if( connector )
{
return connector->get_winix_session_manager();
}
return nullptr;
}
const TimeZones * WinixModel::get_time_zones() const
{
const WinixModelConnector * connector = get_winix_model_connector();
if( connector )
{
return connector->get_winix_time_zones();
}
return nullptr;
}
WinixModelConnector * WinixModel::get_winix_model_connector()
{
if( model_connector )

@ -52,6 +52,9 @@ class Groups;
class SLog;
class Session;
class User;
class Locale;
class SessionManager;
class TimeZones;
@ -69,6 +72,9 @@ public:
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();
Locale * get_locale();
SessionManager * get_session_manager();
TimeZones * get_time_zones();
const Config * get_config() const;
const Request * get_request() const;
@ -80,6 +86,11 @@ public:
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;
const Locale * get_locale() const;
const SessionManager * get_session_manager() const;
const TimeZones * get_time_zones() const;
protected:

@ -50,6 +50,9 @@ WinixModelConnector::WinixModelConnector()
groups = nullptr;
slog = nullptr;
session = nullptr;
locale = nullptr;
session_manager = nullptr;
time_zones = nullptr;
}
@ -107,6 +110,31 @@ Session * WinixModelConnector::get_winix_session()
}
Locale * WinixModelConnector::get_winix_locale()
{
return locale;
}
SessionManager * WinixModelConnector::get_winix_session_manager()
{
return session_manager;
}
TimeZones * WinixModelConnector::get_winix_time_zones()
{
return time_zones;
}
const Config * WinixModelConnector::get_winix_config() const
{
return config;
@ -161,6 +189,24 @@ const Session * WinixModelConnector::get_winix_session() const
}
const Locale * WinixModelConnector::get_winix_locale() const
{
return locale;
}
const SessionManager * WinixModelConnector::get_winix_session_manager() const
{
return session_manager;
}
const TimeZones * WinixModelConnector::get_winix_time_zones() const
{
return time_zones;
}
void WinixModelConnector::set_winix_config(Config * config)
{
@ -216,5 +262,26 @@ void WinixModelConnector::set_winix_session(Session * session)
}
void WinixModelConnector::set_winix_locale(Locale * locale)
{
this->locale = locale;
}
void WinixModelConnector::set_winix_session_manager(SessionManager * session_manager)
{
this->session_manager = session_manager;
}
void WinixModelConnector::set_winix_time_zones(TimeZones * time_zones)
{
this->time_zones = time_zones;
}
}

@ -49,6 +49,9 @@ class Users;
class Groups;
class SLog;
class Session;
class Locale;
class SessionManager;
class TimeZones;
class WinixModelConnector : public morm::ModelConnector
@ -66,6 +69,9 @@ public:
Groups * get_winix_groups();
SLog * get_winix_session_logger();
Session * get_winix_session();
Locale * get_winix_locale();
SessionManager * get_winix_session_manager();
TimeZones * get_winix_time_zones();
const Config * get_winix_config() const;
const Request * get_winix_request() const;
@ -76,6 +82,9 @@ public:
const Groups * get_winix_groups() const;
const SLog * get_winix_session_logger() const;
const Session * get_winix_session() const;
const Locale * get_winix_locale() const;
const SessionManager * get_winix_session_manager() const;
const TimeZones * get_winix_time_zones() const;
void set_winix_config(Config * config);
void set_winix_request(Request * request);
@ -86,6 +95,9 @@ public:
void set_winix_groups(Groups * groups);
void set_winix_session_logger(SLog * slog);
void set_winix_session(Session * session);
void set_winix_locale(Locale * locale);
void set_winix_session_manager(SessionManager * session_manager);
void set_winix_time_zones(TimeZones * time_zones);
protected:
@ -99,6 +111,10 @@ protected:
Groups * groups;
SLog * slog;
Session * session;
Locale * locale;
SessionManager * session_manager;
TimeZones * time_zones;
};

@ -201,24 +201,26 @@ static EzcGen ezc_generator;
//}
void item_can_read(Info & i)
{
i.res = system->HasReadAccess(*cur->request->last_item);
}
// changed to item.has_read_access
//void item_can_read(Info & i)
//{
// i.res = system->HasReadAccess(*cur->request->last_item);
//}
void item_can_write(Info & i)
{
i.res = system->HasWriteAccess(*cur->request->last_item);
}
// changed to item.has_write_access
//void item_can_write(Info & i)
//{
// i.res = system->HasWriteAccess(*cur->request->last_item);
//}
void item_can_remove(Info & i)
{
// !! tutaj trzeba bedzie cos innego zrobic
// zwlaszcza jak dojdzie sticky bit
i.res = system->HasWriteAccess(*cur->request->dir_tab.back());
}
// changed to item.can_be_removed
//void item_can_remove(Info & i)
//{
// // !! tutaj trzeba bedzie cos innego zrobic
// // zwlaszcza jak dojdzie sticky bit
// i.res = system->HasWriteAccess(*cur->request->dir_tab.back());
//}
//void item_user(Info & i)

@ -142,25 +142,12 @@ void print_date_nice(Info & i, const pt::Date & date)
// cannot be a const reference at the moment (pt::Space is used)
void print_user_name(Info & i, User & user)
{
std::wstring * dname = user.aenv.get_wstr(L"display_name");
if( dname && !IsWhite(*dname, true) )
i.out << *dname;
else
i.out << user.name;
}
// IMPROVEME move me to User class
// DEPRECATED, we have ItemContent::display_user_name and User::display_name
void print_user_name(Info & i, User * puser, const std::wstring & guest_name)
{
if( puser )
{
print_user_name(i, *puser);
puser->display_name(i);
}
else
{
@ -176,6 +163,7 @@ void print_user_name(Info & i, User * puser, const std::wstring & guest_name)
} // namespace TemplatesFunctions
} // namespace Winix

@ -74,14 +74,6 @@ void print_hour_min(Info & i, time_t time);
void print_date_nice(Info & i, const pt::Date & date);
/*
print a user name -- it is trying to use 'display_name' from user's admin env
if it not find it or if the 'display_name' is all white (consists of all white characters)
then the login name is printed
*/
void print_user_name(Info & i, User & user);
/*
puser can be null -- in such a case guest_name is used

@ -452,9 +452,9 @@ void Templates::CreateFunctions()
//ezc_functions.Insert("item_has_static_file", item_has_static_file);
// ezc_functions.Insert("item_has_thumb", item_has_thumb);
ezc_functions.Insert("item_can_read", item_can_read);
ezc_functions.Insert("item_can_write", item_can_write);
ezc_functions.Insert("item_can_remove", item_can_remove);
// ezc_functions.Insert("item_can_read", item_can_read);
// ezc_functions.Insert("item_can_write", item_can_write);
// ezc_functions.Insert("item_can_remove", item_can_remove);
//ezc_functions.Insert("item_user", item_user);
ezc_functions.Insert("item_modification_user", item_modification_user);
ezc_functions.Insert("item_users_different", item_users_different);

@ -342,9 +342,9 @@ namespace TemplatesFunctions
//void item_filetype_is_image(Info & i);
//void item_has_static_file(Info & i);
//void item_has_thumb(Info & i);
void item_can_read(Info & i);
void item_can_write(Info & i);
void item_can_remove(Info & i);
// void item_can_read(Info & i);
// void item_can_write(Info & i);
// void item_can_remove(Info & i);
//void item_user(Info & i);
void item_modification_user(Info & i);
void item_users_different(Info & i);

Loading…
Cancel
Save