- updated to the new pikotools api (child spaces were removed)
some plugins need to be fixed yet: ticket, gallery, group, menu - added current user to default models as "user" - renamed in User: super_user -> is_super_user, env -> admin_env, pass_hash_salted -> is_pass_hash_salted - now Users class has a WinixModel as a base class some plugin calls have to be fixed yet - added UserWrapper model with a pointer to User class - removed from ItemContent: methods for accessing 'meta' and 'admin_meta', now ezc can iterate through Space classes - fixed in env winix function: if there is "changeuser" parameter then we should only switch the user (not save anything)
This commit is contained in:
@@ -327,7 +327,7 @@ bool Item::can_remove_child(const User * current_user, long child_user_id) const
|
||||
|
||||
if( type == Type::dir )
|
||||
{
|
||||
if( current_user && current_user->super_user )
|
||||
if( current_user && current_user->is_super_user )
|
||||
{
|
||||
res = true;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,6 @@
|
||||
#include "core/request.h"
|
||||
#include "core/users.h"
|
||||
#include "core/groups.h"
|
||||
#include "templates/miscspace.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
@@ -104,20 +103,6 @@ void ItemContent::fields()
|
||||
field(L"has_thumb", &ItemContent::has_thumb);
|
||||
field(L"display_user_name", &ItemContent::display_user_name);
|
||||
|
||||
field(L"meta_to_str", &ItemContent::meta_to_str);
|
||||
field(L"meta_prop", &ItemContent::meta_prop);
|
||||
field(L"meta_prop_no_escape", &ItemContent::meta_prop_no_escape);
|
||||
field(L"meta_prop_tab", &ItemContent::meta_prop_tab);
|
||||
field(L"meta_prop_tab_value", &ItemContent::meta_prop_tab_value);
|
||||
field(L"meta_prop_tab_has_next",&ItemContent::meta_prop_tab_has_next);
|
||||
|
||||
field(L"admin_meta_to_str", &ItemContent::admin_meta_to_str);
|
||||
field(L"admin_meta_prop", &ItemContent::admin_meta_prop);
|
||||
field(L"admin_meta_prop_no_escape", &ItemContent::admin_meta_prop_no_escape);
|
||||
field(L"admin_meta_prop_tab", &ItemContent::admin_meta_prop_tab);
|
||||
field(L"admin_meta_prop_tab_value", &ItemContent::admin_meta_prop_tab_value);
|
||||
field(L"admin_meta_prop_tab_has_next", &ItemContent::admin_meta_prop_tab_has_next);
|
||||
|
||||
|
||||
// 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);
|
||||
@@ -268,16 +253,7 @@ bool ItemContent::do_migration_to_3()
|
||||
};
|
||||
|
||||
size_t len = sizeof(str) / sizeof(const char*);
|
||||
|
||||
for(size_t i=0 ; i < len ; ++i)
|
||||
{
|
||||
if( !db_query(str[i]) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return db_query(str, len);
|
||||
}
|
||||
|
||||
|
||||
@@ -285,7 +261,7 @@ bool ItemContent::has_access(const User * current_user, int mask) const
|
||||
{
|
||||
if( current_user )
|
||||
{
|
||||
if( current_user->super_user )
|
||||
if( current_user->is_super_user )
|
||||
{
|
||||
// super user is allowed everything
|
||||
return true;
|
||||
@@ -332,7 +308,7 @@ bool ItemContent::has_read_write_access(const User * current_user) const
|
||||
|
||||
bool ItemContent::has_read_exec_access(const User * current_user) const
|
||||
{
|
||||
if( current_user && current_user->super_user )
|
||||
if( current_user && current_user->is_super_user )
|
||||
{
|
||||
// there must be at least one 'x' (for the root)
|
||||
// !! CHECK ME: is it applicable to directories too?
|
||||
@@ -492,23 +468,30 @@ void ItemContent::group(morm::ModelWrapper ** model_wrapper)
|
||||
}
|
||||
|
||||
|
||||
bool ItemContent::content_type_is(const std::wstring & type)
|
||||
{
|
||||
if( content_raw_type == ItemContent::ct_text && type == L"text" )
|
||||
return true;
|
||||
else
|
||||
if( content_raw_type == ItemContent::ct_formatted_text && type == L"formatted text" )
|
||||
return true;
|
||||
else
|
||||
if( content_raw_type == ItemContent::ct_html && type == L"html" )
|
||||
return true;
|
||||
else
|
||||
if( content_raw_type == ItemContent::ct_bbcode && type == L"bbcode" )
|
||||
return true;
|
||||
else
|
||||
if( content_raw_type == ItemContent::ct_other && type == L"other" )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
env.res = content_type_is(env.par);
|
||||
}
|
||||
|
||||
|
||||
@@ -603,79 +586,6 @@ void ItemContent::display_user_name(EzcEnv & env)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* IMPROVEME may it would be better to browse by Space struct in the same way as in Models?
|
||||
* so Model should have support for it
|
||||
*
|
||||
*/
|
||||
void ItemContent::meta_to_str(EzcEnv & env)
|
||||
{
|
||||
meta.serialize_to_space_stream(env.out, true);
|
||||
}
|
||||
|
||||
void ItemContent::meta_prop(EzcEnv & env)
|
||||
{
|
||||
TemplatesFunctions::space_value(env, meta);
|
||||
}
|
||||
|
||||
void ItemContent::meta_prop_no_escape(EzcEnv & env)
|
||||
{
|
||||
TemplatesFunctions::space_value(env, meta, false);
|
||||
}
|
||||
|
||||
|
||||
void ItemContent::meta_prop_tab(EzcEnv & env)
|
||||
{
|
||||
TemplatesFunctions::space_list_tab(env, meta);
|
||||
}
|
||||
|
||||
void ItemContent::meta_prop_tab_value(EzcEnv & env)
|
||||
{
|
||||
// FIXME there is no "item_meta_tab" now
|
||||
TemplatesFunctions::space_list_tab_value(env, meta, L"item_meta_tab");
|
||||
}
|
||||
|
||||
void ItemContent::meta_prop_tab_has_next(EzcEnv & env)
|
||||
{
|
||||
// FIXME there is no "item_meta_tab" now
|
||||
TemplatesFunctions::space_list_tab_has_next(env, meta, L"item_meta_tab");
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ItemContent::admin_meta_to_str(EzcEnv & env)
|
||||
{
|
||||
meta_admin.serialize_to_space_stream(env.out, true);
|
||||
}
|
||||
|
||||
void ItemContent::admin_meta_prop(EzcEnv & env)
|
||||
{
|
||||
TemplatesFunctions::space_value(env, meta_admin);
|
||||
}
|
||||
|
||||
void ItemContent::admin_meta_prop_no_escape(EzcEnv & env)
|
||||
{
|
||||
TemplatesFunctions::space_value(env, meta_admin, false);
|
||||
}
|
||||
|
||||
|
||||
void ItemContent::admin_meta_prop_tab(EzcEnv & env)
|
||||
{
|
||||
TemplatesFunctions::space_list_tab(env, meta_admin);
|
||||
}
|
||||
|
||||
void ItemContent::admin_meta_prop_tab_value(EzcEnv & env)
|
||||
{
|
||||
// FIXME there is no "item_admin_meta_tab" now
|
||||
TemplatesFunctions::space_list_tab_value(env, meta_admin, L"item_admin_meta_tab");
|
||||
}
|
||||
|
||||
void ItemContent::admin_meta_prop_tab_has_next(EzcEnv & env)
|
||||
{
|
||||
// FIXME there is no "item_admin_meta_tab" now
|
||||
TemplatesFunctions::space_list_tab_has_next(env, meta_admin, L"item_admin_meta_tab");
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
@@ -280,6 +280,7 @@ protected:
|
||||
bool do_migration_to_3();
|
||||
|
||||
bool has_access(const User * current_user, int mask) const;
|
||||
bool content_type_is(const std::wstring & type);
|
||||
|
||||
void print_content(EzcEnv & env);
|
||||
void has_static_file(EzcEnv & env);
|
||||
@@ -294,18 +295,7 @@ protected:
|
||||
void file_type_is_sound(EzcEnv & env);
|
||||
void has_thumb(EzcEnv & env);
|
||||
void display_user_name(EzcEnv & env);
|
||||
void meta_to_str(EzcEnv & env);
|
||||
void meta_prop(EzcEnv & env);
|
||||
void meta_prop_no_escape(EzcEnv & env);
|
||||
void meta_prop_tab(EzcEnv & env);
|
||||
void meta_prop_tab_value(EzcEnv & env);
|
||||
void meta_prop_tab_has_next(EzcEnv & env);
|
||||
void admin_meta_to_str(EzcEnv & env);
|
||||
void admin_meta_prop(EzcEnv & env);
|
||||
void admin_meta_prop_no_escape(EzcEnv & env);
|
||||
void admin_meta_prop_tab(EzcEnv & env);
|
||||
void admin_meta_prop_tab_value(EzcEnv & env);
|
||||
void admin_meta_prop_tab_has_next(EzcEnv & env);
|
||||
|
||||
|
||||
MORM_MEMBER_FIELD(ItemContent)
|
||||
|
||||
|
||||
@@ -53,22 +53,28 @@ 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); // IMPROVEME rename to is_super_user
|
||||
field(L"login", login);
|
||||
field(L"is_super_user", 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"is_pass_hash_salted", 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"admin_env", admin_env);
|
||||
field(L"status", status);
|
||||
field(L"locale_id", locale_id);
|
||||
field(L"time_zone_id", time_zone_id);
|
||||
|
||||
field(L"", L"id_is", &User::id_is);
|
||||
field(L"", L"is_guest", &User::is_guest);
|
||||
field(L"", L"is_env_object", &User::is_env_object);
|
||||
field(L"", L"is_admin_env_object", &User::is_admin_env_object);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -95,20 +101,20 @@ void User::after_insert()
|
||||
void User::Clear()
|
||||
{
|
||||
id = -1;
|
||||
name.clear();
|
||||
super_user = false;
|
||||
login.clear();
|
||||
is_super_user = false;
|
||||
groups.clear();
|
||||
email.clear();
|
||||
notify = 0;
|
||||
env.clear();
|
||||
aenv.clear();
|
||||
admin_env.clear();
|
||||
status = WINIX_ACCOUNT_BLOCKED;
|
||||
locale_id = 0;
|
||||
time_zone_id = 0;
|
||||
|
||||
has_pass = false;
|
||||
pass_type = 0;
|
||||
pass_hash_salted = false;
|
||||
is_pass_hash_salted = false;
|
||||
clear_passwords();
|
||||
}
|
||||
|
||||
@@ -143,6 +149,7 @@ bool User::do_migration(int & current_table_version)
|
||||
bool ok = true;
|
||||
|
||||
ok = ok && morm::Model::do_migration(current_table_version, 1, this, &User::do_migration_to_1);
|
||||
ok = ok && morm::Model::do_migration(current_table_version, 2, this, &User::do_migration_to_2);
|
||||
|
||||
return ok;
|
||||
}
|
||||
@@ -160,11 +167,11 @@ bool User::do_migration_to_1()
|
||||
email character varying(255),
|
||||
notify integer,
|
||||
pass_type integer,
|
||||
pass_hash_salted boolean,
|
||||
is_pass_hash_salted boolean,
|
||||
pass_encrypted bytea,
|
||||
super_user boolean,
|
||||
is_super_user boolean,
|
||||
env text,
|
||||
aenv text,
|
||||
admin_env text,
|
||||
status integer,
|
||||
locale_id integer,
|
||||
time_zone_id integer,
|
||||
@@ -177,18 +184,57 @@ bool User::do_migration_to_1()
|
||||
}
|
||||
|
||||
|
||||
bool User::do_migration_to_2()
|
||||
{
|
||||
const char * str[] = {
|
||||
"alter table core.user rename column aenv to admin_env",
|
||||
"alter table core.user rename column super_user to is_super_user",
|
||||
"alter table core.user rename column pass_hash_salted to is_pass_hash_salted",
|
||||
};
|
||||
|
||||
size_t len = sizeof(str) / sizeof(const char*);
|
||||
return db_query(str, len);
|
||||
}
|
||||
|
||||
|
||||
void User::display_name(EzcEnv & env)
|
||||
{
|
||||
std::wstring * dname = aenv.get_wstr(L"display_name");
|
||||
std::wstring * dname = admin_env.get_wstr(L"display_name");
|
||||
|
||||
if( dname && !IsWhite(*dname, true) )
|
||||
env.out << *dname;
|
||||
else
|
||||
env.out << name;
|
||||
env.out << login;
|
||||
}
|
||||
|
||||
|
||||
void User::id_is(EzcEnv & env)
|
||||
{
|
||||
if( !env.par.empty() )
|
||||
{
|
||||
long par_user_id = pt::Tol(env.par.c_str());
|
||||
env.res = id == par_user_id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool User::is_guest()
|
||||
{
|
||||
return id == -1;
|
||||
}
|
||||
|
||||
|
||||
bool User::is_env_object()
|
||||
{
|
||||
return env.is_object();
|
||||
}
|
||||
|
||||
|
||||
bool User::is_admin_env_object()
|
||||
{
|
||||
return admin_env.is_object();
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include "space/space.h"
|
||||
#include "date/date.h"
|
||||
#include "templates/misc.h"
|
||||
#include "winixmodel.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
@@ -86,13 +87,13 @@ namespace Winix
|
||||
(when the pointer is not null then winix do not check what the value of 'status' is --
|
||||
the status is only tested in 'login' function)
|
||||
*/
|
||||
class User : public morm::Model
|
||||
class User : public WinixModel
|
||||
{
|
||||
public:
|
||||
|
||||
long id;
|
||||
std::wstring name;
|
||||
bool super_user;
|
||||
std::wstring login;
|
||||
bool is_super_user;
|
||||
|
||||
|
||||
bool has_pass; // true if the user has a password set
|
||||
@@ -100,7 +101,7 @@ public:
|
||||
int pass_type; // the kind of hash (WINIX_CRYPT_HASH_* see crypt.h)
|
||||
std::wstring password; // password hashed or plain text if pass_type==0
|
||||
std::string pass_encrypted; // password encrypted
|
||||
bool pass_hash_salted; // true when the hash was salted (plain text passwords are never salted)
|
||||
bool is_pass_hash_salted; // true when the hash was salted (plain text passwords are never salted)
|
||||
|
||||
|
||||
std::wstring email;
|
||||
@@ -113,7 +114,7 @@ public:
|
||||
// environment variables set only by an administrator
|
||||
// an administrator can use 'env' winix function with 'a' parameter
|
||||
// IMPROVEME rename me to something better (env_admin?)
|
||||
pt::Space aenv;
|
||||
pt::Space admin_env;
|
||||
|
||||
// account status
|
||||
// WINIX_ACCOUNT_*
|
||||
@@ -149,11 +150,21 @@ public:
|
||||
void display_name(EzcEnv & env);
|
||||
|
||||
|
||||
bool is_env_object();
|
||||
bool is_admin_env_object();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
bool do_migration_to_1();
|
||||
bool do_migration_to_2();
|
||||
|
||||
void id_is(EzcEnv & env); // takes one argument as a user id
|
||||
bool is_guest();
|
||||
|
||||
|
||||
|
||||
MORM_MEMBER_FIELD(User)
|
||||
};
|
||||
|
||||
|
||||
|
||||
88
winixd/models/userwrapper.h
Normal file
88
winixd/models/userwrapper.h
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2021, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_winix_models_userhelper
|
||||
#define headerfile_winix_models_userhelper
|
||||
|
||||
#include "user.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
class UserWrapper : public WinixModel
|
||||
{
|
||||
public:
|
||||
|
||||
User * user;
|
||||
|
||||
|
||||
UserWrapper()
|
||||
{
|
||||
user = nullptr;
|
||||
}
|
||||
|
||||
|
||||
void fields()
|
||||
{
|
||||
field(L"", L"user", &UserWrapper::get_user);
|
||||
field(L"", L"has_user", &UserWrapper::has_user);
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
void get_user(morm::ModelWrapper ** model_wrapper)
|
||||
{
|
||||
if( user )
|
||||
{
|
||||
*model_wrapper = new morm::ModelWrapperModel(user);
|
||||
}
|
||||
}
|
||||
|
||||
bool has_user()
|
||||
{
|
||||
return user != nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
MORM_MEMBER_FIELD(UserWrapper)
|
||||
};
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user