2021-02-24 01:19:47 +01:00
|
|
|
/*
|
|
|
|
* 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) 2008-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_item
|
|
|
|
#define headerfile_winix_models_item
|
|
|
|
|
|
|
|
#include <string>
|
2021-06-16 18:07:44 +02:00
|
|
|
#include "winixmodel.h"
|
|
|
|
#include "itemcontent.h"
|
2021-05-31 18:59:20 +02:00
|
|
|
#include "funinfo.h"
|
|
|
|
#include "templates/htmltextstream.h"
|
2021-06-18 19:18:13 +02:00
|
|
|
#include "templates/misc.h"
|
2021-05-31 18:59:20 +02:00
|
|
|
|
|
|
|
|
2021-04-14 14:13:47 +02:00
|
|
|
|
2021-02-24 01:19:47 +01:00
|
|
|
namespace Winix
|
|
|
|
{
|
|
|
|
|
|
|
|
// IMPROVEME rename me and move to a better place
|
|
|
|
class CalcItemsHelper : public morm::Model
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
long size;
|
2021-03-08 21:06:50 +01:00
|
|
|
long item_id;
|
2021-02-25 00:12:45 +01:00
|
|
|
|
2021-05-13 03:29:41 +02:00
|
|
|
|
|
|
|
void fields()
|
2021-02-24 01:19:47 +01:00
|
|
|
{
|
|
|
|
field(L"size", size);
|
2021-03-08 21:06:50 +01:00
|
|
|
field(L"item_id", item_id);
|
|
|
|
}
|
|
|
|
|
2021-05-13 03:29:41 +02:00
|
|
|
void table()
|
2021-04-09 17:50:58 +02:00
|
|
|
{
|
2021-05-13 03:29:41 +02:00
|
|
|
table_name(L"core", L"item");
|
2021-04-09 17:50:58 +02:00
|
|
|
}
|
|
|
|
|
2021-03-08 21:06:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// IMPROVEME rename me and move to a better place
|
|
|
|
class ItemModelData : public morm::ModelData
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
ItemModelData()
|
|
|
|
{
|
|
|
|
prepare_unique_url = true;
|
2021-02-24 01:19:47 +01:00
|
|
|
}
|
|
|
|
|
2021-03-08 21:06:50 +01:00
|
|
|
bool prepare_unique_url;
|
2021-02-24 01:19:47 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-06-16 18:07:44 +02:00
|
|
|
class Item : public WinixModel
|
2021-02-24 01:19:47 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
|
|
enum Type
|
|
|
|
{
|
|
|
|
dir = 0,
|
|
|
|
file = 1,
|
|
|
|
symlink = 2,
|
|
|
|
|
|
|
|
none = 1000
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
long id;
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
long parent_id;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* may change to int?
|
|
|
|
*/
|
|
|
|
Type type;
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
std::wstring url;
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
std::wstring subject;
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
std::wstring html_template;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sort index used when displaying a group of items
|
|
|
|
*/
|
|
|
|
int sort_index;
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
ItemContent item_content;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Item();
|
|
|
|
|
2021-05-13 03:29:41 +02:00
|
|
|
void fields();
|
|
|
|
void table();
|
2021-02-24 01:19:47 +01:00
|
|
|
void before_insert();
|
|
|
|
void after_insert();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* what about clear() from Model?
|
|
|
|
*/
|
|
|
|
void Clear();
|
|
|
|
|
|
|
|
|
|
|
|
bool prepare_url();
|
|
|
|
|
|
|
|
|
2021-03-08 21:06:50 +01:00
|
|
|
using morm::Model::insert;
|
|
|
|
using morm::Model::update;
|
2021-02-25 00:12:45 +01:00
|
|
|
|
|
|
|
bool insert(morm::ModelData * model_data, bool update_whole_tree = true);
|
2021-03-08 21:06:50 +01:00
|
|
|
bool update(morm::ModelData * model_data, bool update_whole_tree = true);
|
2021-02-24 01:19:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* IMPROVEME
|
2021-02-25 00:12:45 +01:00
|
|
|
* when removing we should check whether the item_content.references is zero and then remove it
|
2021-02-24 01:19:47 +01:00
|
|
|
* in other cases only decrement item_content.references
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2021-05-14 03:31:29 +02:00
|
|
|
bool do_migration(int & current_table_version);
|
2021-02-24 01:19:47 +01:00
|
|
|
|
2021-03-08 21:06:50 +01:00
|
|
|
void propagate_connector();
|
|
|
|
|
2021-06-18 19:18:13 +02:00
|
|
|
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;
|
2021-05-14 03:31:29 +02:00
|
|
|
|
2021-06-20 18:04:50 +02:00
|
|
|
bool has_read_access() const;
|
|
|
|
bool has_write_access() const;
|
|
|
|
bool has_read_write_access() const;
|
|
|
|
bool has_read_exec_access() const;
|
2021-06-18 19:18:13 +02:00
|
|
|
|
|
|
|
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;
|
2021-06-16 18:07:44 +02:00
|
|
|
|
2021-07-06 21:52:29 +02:00
|
|
|
bool has_html_template();
|
2021-05-31 18:59:20 +02:00
|
|
|
|
2021-02-24 01:19:47 +01:00
|
|
|
protected:
|
|
|
|
|
2021-03-08 21:06:50 +01:00
|
|
|
CalcItemsHelper calc_items_by_url(long parent_id, const std::wstring & url);
|
2021-02-24 01:19:47 +01:00
|
|
|
|
2021-05-14 03:31:29 +02:00
|
|
|
bool do_migration_to_1();
|
|
|
|
bool do_migration_to_2();
|
|
|
|
bool do_migration_to_3();
|
|
|
|
bool do_migration_to_4();
|
2021-02-24 01:19:47 +01:00
|
|
|
|
2021-06-18 19:18:13 +02:00
|
|
|
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);
|
2021-06-20 18:04:50 +02:00
|
|
|
void execute(EzcEnv & env);
|
2021-06-18 19:18:13 +02:00
|
|
|
|
|
|
|
|
2021-06-16 18:07:44 +02:00
|
|
|
MORM_MEMBER_FIELD(Item)
|
2021-06-18 19:18:13 +02:00
|
|
|
|
2021-02-24 01:19:47 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace Winix
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|