Skip to content

Commit

Permalink
Improve the Session_Logic
Browse files Browse the repository at this point in the history
  • Loading branch information
teusbenschop committed Jun 7, 2024
1 parent e2cdda9 commit baafcef
Show file tree
Hide file tree
Showing 80 changed files with 270 additions and 283 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ server
*.in~
*.tar.gz
configure~
libbibledit.a.*

12 changes: 6 additions & 6 deletions access/bible.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ bool read (Webserver_Request& webserver_request, const std::string& bible, std::
int role_level { 0 };
if (user.empty ()) {
// Current user.
user = webserver_request.session_logic ()->currentUser ();
role_level = webserver_request.session_logic ()->currentLevel ();
user = webserver_request.session_logic ()->get_username ();
role_level = webserver_request.session_logic ()->get_level ();
} else {
// Take level belonging to user.
role_level = webserver_request.database_users ()->get_level (user);
Expand Down Expand Up @@ -91,8 +91,8 @@ bool write (Webserver_Request& webserver_request, const std::string& bible, std:

int level {0};
if (user.empty ()) {
user = webserver_request.session_logic ()->currentUser ();
level = webserver_request.session_logic ()->currentLevel ();
user = webserver_request.session_logic ()->get_username ();
level = webserver_request.session_logic ()->get_level ();
}
if (level == 0) {
// Take level belonging to user.
Expand Down Expand Up @@ -140,8 +140,8 @@ bool book_write (Webserver_Request& webserver_request, std::string user, const s
// Get the user level (role).
int level {0};
if (user.empty ()) {
user = webserver_request.session_logic ()->currentUser ();
level = webserver_request.session_logic ()->currentLevel ();
user = webserver_request.session_logic ()->get_username ();
level = webserver_request.session_logic ()->get_level ();
}
if (level == 0) {
// Take level belonging to user.
Expand Down
4 changes: 2 additions & 2 deletions access/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ void user_level (Webserver_Request& webserver_request, std::string& user, int& l
{
if (user.empty ()) {
// If no user is given, take the user from the session.
user = webserver_request.session_logic ()->currentUser ();
level = webserver_request.session_logic ()->currentLevel ();
user = webserver_request.session_logic ()->get_username ();
level = webserver_request.session_logic ()->get_level ();
} else {
// If a user is given, take the matching level from the database.
level = webserver_request.database_users ()->get_level (user);
Expand Down
4 changes: 2 additions & 2 deletions access/user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
// This function returns users assigned to the logged-in user.
std::vector <std::string> access_user::assignees (Webserver_Request& webserver_request)
{
const std::string myuser = webserver_request.session_logic ()->currentUser ();
const int mylevel = webserver_request.session_logic ()->currentLevel ();
const std::string& myuser = webserver_request.session_logic ()->get_username ();
const int mylevel = webserver_request.session_logic ()->get_level ();

// This holds the assignees.
std::vector <std::string> assignees {};
Expand Down
4 changes: 2 additions & 2 deletions assets/header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ std::string Assets_Header::run ()
m_view->enable_zone ("include_jquery_touch");
}

if (m_webserver_request.session_logic ()->touchEnabled ()) {
if (m_webserver_request.session_logic ()->get_touch_enabled ()) {
touch_css_on();
}
if (!m_webserver_request.session_logic ()->loggedIn ()) {
if (!m_webserver_request.session_logic ()->get_logged_in ()) {
touch_css_on();
}
if (m_touch_css_on) {
Expand Down
4 changes: 2 additions & 2 deletions bb/manage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ std::string bible_manage (Webserver_Request& webserver_request)
database::bibles::create_bible (bible);
// Check / grant access.
if (!access_bible::write (webserver_request, bible)) {
std::string me = webserver_request.session_logic()->currentUser ();
const std::string& me = webserver_request.session_logic ()->get_username ();
DatabasePrivileges::set_bible (me, bible, true);
}
success_message = translate("The Bible was created");
Expand Down Expand Up @@ -134,7 +134,7 @@ std::string bible_manage (Webserver_Request& webserver_request)
success_message = translate("The Bible was copied.");
// Check / grant access to destination Bible.
if (!access_bible::write (webserver_request, destination)) {
const std::string me = webserver_request.session_logic ()->currentUser ();
const std::string& me = webserver_request.session_logic ()->get_username ();
DatabasePrivileges::set_bible (me, destination, true);
}
// Creating a Bible removes any Sample Bible that might have been there.
Expand Down
4 changes: 2 additions & 2 deletions bb/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ std::string bible_settings (Webserver_Request& webserver_request)


// Whether the user has the privilege to change the stylesheet.
const std::string current_user = webserver_request.session_logic()->currentUser ();
const std::string& current_user = webserver_request.session_logic ()->get_username ();
bool privilege_stylesheet = access_logic::privilege_set_stylesheets (webserver_request, current_user);
if (privilege_stylesheet) view.enable_zone ("privilege_stylesheet");

Expand Down Expand Up @@ -196,7 +196,7 @@ std::string bible_settings (Webserver_Request& webserver_request)
}


const int level = webserver_request.session_logic ()->currentLevel ();
const int level = webserver_request.session_logic ()->get_level ();
const bool manager_level = (level >= Filter_Roles::manager ());
if (manager_level) view.enable_zone ("manager");

Expand Down
6 changes: 3 additions & 3 deletions changes/change.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ std::string changes_change (Webserver_Request& webserver_request)
if (webserver_request.post.count ("unassign")) {
std::string unassign = webserver_request.post["unassign"];
unassign.erase (0, 8);
notes_logic.unassignUser (filter::strings::convert_to_int (unassign), webserver_request.session_logic()->currentUser ());
notes_logic.unassignUser (filter::strings::convert_to_int (unassign), webserver_request.session_logic ()->get_username ());
return std::string();
}

Expand All @@ -97,8 +97,8 @@ std::string changes_change (Webserver_Request& webserver_request)

// From here on the script will produce output.
Assets_View view {};
const std::string username {webserver_request.session_logic()->currentUser ()};
const int level {webserver_request.session_logic ()->currentLevel ()};
const std::string& username {webserver_request.session_logic ()->get_username ()};
const int level {webserver_request.session_logic ()->get_level ()};


// The identifier of the change notification.
Expand Down
4 changes: 2 additions & 2 deletions changes/changes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ std::string changes_changes (Webserver_Request& webserver_request)
}


const std::string username = webserver_request.session_logic()->currentUser ();
const bool touch = webserver_request.session_logic ()->touchEnabled ();
const std::string& username = webserver_request.session_logic ()->get_username ();
const bool touch = webserver_request.session_logic ()->get_touch_enabled ();


std::string page {};
Expand Down
2 changes: 1 addition & 1 deletion client/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void client_index_enable_client (Webserver_Request& webserver_request, const std

// Update the username and the level in the current session.
webserver_request.session_logic ()->set_username (username);
webserver_request.session_logic ()->currentLevel (true);
webserver_request.session_logic ()->get_level (true);

// If there's pending Bible updates, send them off to the user.
bible_logic::client_mail_pending_bible_updates (username);
Expand Down
2 changes: 1 addition & 1 deletion config/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ void swipe_enabled (Webserver_Request& webserver_request, std::string& script)
{
bool swipe_operations {false};
std::string true_false {"false"};
if (webserver_request.session_logic ()->touchEnabled ()) {
if (webserver_request.session_logic ()->get_touch_enabled ()) {
if (webserver_request.database_config_user ()->getSwipeActionsAvailable ()) {
true_false = "true";
swipe_operations = true;
Expand Down
12 changes: 6 additions & 6 deletions database/config/user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ std::string Database_Config_User::mapkey (const std::string& user, const char *

std::string Database_Config_User::getValue (const char * key, const char * default_value) const
{
const std::string user = m_webserver_request.session_logic ()->currentUser ();
const std::string& user = m_webserver_request.session_logic ()->get_username ();
return getValueForUser (user, key, default_value);
}

Expand Down Expand Up @@ -125,7 +125,7 @@ int Database_Config_User::getIValueForUser (const std::string& user, const char

void Database_Config_User::setValue (const char * key, const std::string& value) const
{
const std::string user = m_webserver_request.session_logic ()->currentUser ();
const std::string& user = m_webserver_request.session_logic ()->get_username ();
setValueForUser (user, key, value);
}

Expand Down Expand Up @@ -163,7 +163,7 @@ void Database_Config_User::setBValueForUser (const std::string& user, const char

std::vector <std::string> Database_Config_User::getList (const char * key) const
{
const std::string user = m_webserver_request.session_logic ()->currentUser ();
const std::string& user = m_webserver_request.session_logic ()->get_username ();
return getListForUser (user, key);
}

Expand Down Expand Up @@ -192,7 +192,7 @@ std::vector <std::string> Database_Config_User::getListForUser (const std::strin

void Database_Config_User::setList (const char * key, const std::vector <std::string>& values) const
{
const std::string user = m_webserver_request.session_logic ()->currentUser ();
const std::string& user = m_webserver_request.session_logic ()->get_username ();
setListForUser (user, key, values);
}

Expand Down Expand Up @@ -567,7 +567,7 @@ bool Database_Config_User::default_bible_checks_notification () const
#ifdef HAVE_CLIENT
return false;
#else
const int level = m_webserver_request.session_logic ()->currentLevel ();
const int level = m_webserver_request.session_logic ()->get_level ();
return (level >= Filter_Roles::translator () && level <= Filter_Roles::manager ());
#endif
}
Expand Down Expand Up @@ -1194,7 +1194,7 @@ bool Database_Config_User::getBasicInterfaceModeDefault () const
return true;
#endif
// The app running on a workspace or laptop have default to basic mode for a lower role.
const int level = m_webserver_request.session_logic ()->currentLevel ();
const int level = m_webserver_request.session_logic ()->get_level ();
if (level <= Filter_Roles::manager ())
return true;
// Higher role: default to advanced mode.
Expand Down
6 changes: 3 additions & 3 deletions database/ipc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void Database_Ipc::deleteMessage (int id)

std::string Database_Ipc::getFocus ()
{
std::string user = m_webserver_request.session_logic ()->currentUser ();
const std::string& user = m_webserver_request.session_logic ()->get_username ();

int highestId = 0;
std::string hitMessage = "";
Expand All @@ -169,7 +169,7 @@ std::string Database_Ipc::getFocus ()

Database_Ipc_Message Database_Ipc::getNote ()
{
std::string user = m_webserver_request.session_logic ()->currentUser ();
const std::string& user = m_webserver_request.session_logic ()->get_username ();

int highestId = 0;
std::string hitMessage = "";
Expand Down Expand Up @@ -200,7 +200,7 @@ Database_Ipc_Message Database_Ipc::getNote ()

bool Database_Ipc::getNotesAlive ()
{
std::string user = m_webserver_request.session_logic ()->currentUser ();
const std::string& user = m_webserver_request.session_logic ()->get_username ();

int highestId = 0;
std::string hitMessage = "";
Expand Down
4 changes: 2 additions & 2 deletions database/mail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void Database_Mail::send (std::string to, std::string subject, std::string body,
// Get number of mails for the current user.
int Database_Mail::getMailCount ()
{
std::string user = m_webserver_request.session_logic ()->currentUser();
const std::string& user = m_webserver_request.session_logic ()->get_username();
SqliteSQL sql = SqliteSQL ();
sql.add ("SELECT count(*) FROM mail WHERE username =");
sql.add (user);
Expand All @@ -132,7 +132,7 @@ int Database_Mail::getMailCount ()
std::vector <Database_Mail_User> Database_Mail::getMails ()
{
std::vector <Database_Mail_User> mails;
std::string user = m_webserver_request.session_logic ()->currentUser();
const std::string& user = m_webserver_request.session_logic ()->get_username();
SqliteSQL sql = SqliteSQL ();
sql.add ("SELECT rowid, timestamp, subject FROM mail WHERE username =");
sql.add (user);
Expand Down
8 changes: 4 additions & 4 deletions database/notes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ std::string Database_Notes::assemble_contents (int identifier, std::string conte
{
std::string new_contents = get_contents (identifier);
std::string datetime = filter::date::localized_date_format (m_webserver_request);
std::string user = m_webserver_request.session_logic ()->currentUser ();
const std::string& user = m_webserver_request.session_logic ()->get_username ();
// To make the notes more readable, add whitespace between the comments.
bool is_initial_comment = new_contents.empty ();
if (!is_initial_comment) {
Expand Down Expand Up @@ -621,7 +621,7 @@ int Database_Notes::store_new_note (const std::string& bible, int book, int chap
// limit: If >= 0, it indicates the starting limit for the selection.
std::vector <int> Database_Notes::select_notes (std::vector <std::string> bibles, int book, int chapter, int verse, int passage_selector, int edit_selector, int non_edit_selector, const std::string& status_selector, std::string bible_selector, std::string assignment_selector, bool subscription_selector, int severity_selector, int text_selector, const std::string& search_text, int limit)
{
std::string username = m_webserver_request.session_logic ()->currentUser ();
const std::string& username = m_webserver_request.session_logic ()->get_username ();
std::vector <int> identifiers;
// SQL SELECT statement.
std::string query = notes_select_identifier ();
Expand Down Expand Up @@ -902,7 +902,7 @@ void Database_Notes::add_comment (int identifier, const std::string& comment)
// Subscribe the current user to the note identified by identifier.
void Database_Notes::subscribe (int identifier)
{
std::string user = m_webserver_request.session_logic ()->currentUser ();
const std::string& user = m_webserver_request.session_logic ()->get_username ();
subscribe_user (identifier, user);
}

Expand Down Expand Up @@ -984,7 +984,7 @@ bool Database_Notes::is_subscribed (int identifier, const std::string& user)
// Unsubscribes the currently logged in user from the note identified by identifier.
void Database_Notes::unsubscribe (int identifier)
{
std::string user = m_webserver_request.session_logic ()->currentUser ();
const std::string& user = m_webserver_request.session_logic ()->get_username ();
unsubscribe_user (identifier, user);
}

Expand Down
2 changes: 1 addition & 1 deletion developer/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Developer_Logic_Tracer::Developer_Logic_Tracer(Webserver_Request& webserver_requ
request_query.append("=");
request_query.append(element.second);
}
username = webserver_request.session_logic()->currentUser();
username = webserver_request.session_logic ()->get_username();
}


Expand Down
2 changes: 1 addition & 1 deletion edit/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ bool edit_index_acl (Webserver_Request& webserver_request)

std::string edit_index (Webserver_Request& webserver_request)
{
const bool touch = webserver_request.session_logic ()->touchEnabled ();
const bool touch = webserver_request.session_logic ()->get_touch_enabled ();


if (webserver_request.query.count ("switchbook") && webserver_request.query.count ("switchchapter")) {
Expand Down
2 changes: 1 addition & 1 deletion edit/load.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ std::string edit_load (Webserver_Request& webserver_request)
html = filter::strings::replace (search, replace, html);
}

const std::string user = webserver_request.session_logic ()->currentUser ();
const std::string& user = webserver_request.session_logic ()->get_username ();
const bool write = access_bible::book_write (webserver_request, user, bible, book);

return checksum_logic::send (html, write);
Expand Down
2 changes: 1 addition & 1 deletion edit/preview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ bool edit_preview_acl (Webserver_Request& webserver_request)

std::string edit_preview (Webserver_Request& webserver_request)
{
bool touch = webserver_request.session_logic ()->touchEnabled ();
bool touch = webserver_request.session_logic ()->get_touch_enabled ();
bool timeout = webserver_request.query.count ("timeout");
std::string caller = webserver_request.query ["caller"];

Expand Down
2 changes: 1 addition & 1 deletion edit/save.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ std::string edit_save (Webserver_Request& webserver_request)

// Collect some data about the changes for this user
// and for a possible merge of the user's data with the server's data.
std::string username = webserver_request.session_logic()->currentUser ();
const std::string& username = webserver_request.session_logic ()->get_username ();
[[maybe_unused]] int oldID = database::bibles::get_chapter_id (bible, book, chapter);
std::string server_usfm = database::bibles::get_chapter (bible, book, chapter);
std::string newText = user_usfm;
Expand Down
2 changes: 1 addition & 1 deletion edit/update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ std::string edit_update (Webserver_Request& webserver_request)


// Collect some data about the changes for this user.
std::string username = webserver_request.session_logic()->currentUser ();
const std::string& username = webserver_request.session_logic ()->get_username ();
#ifdef HAVE_CLOUD
int oldID = 0;
if (good2go) {
Expand Down
2 changes: 1 addition & 1 deletion editone2/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ bool editone2_index_acl (Webserver_Request& webserver_request)

std::string editone2_index (Webserver_Request& webserver_request)
{
const bool touch = webserver_request.session_logic ()->touchEnabled ();
const bool touch = webserver_request.session_logic ()->get_touch_enabled ();

if (webserver_request.query.count ("switchbook") && webserver_request.query.count ("switchchapter")) {
const int switchbook = filter::strings::convert_to_int (webserver_request.query ["switchbook"]);
Expand Down
2 changes: 1 addition & 1 deletion editone2/load.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ std::string editone2_load (Webserver_Request& webserver_request)
data.append ("#_be_#");
data.append (suffix_html);

std::string user = webserver_request.session_logic ()->currentUser ();
const std::string& user = webserver_request.session_logic ()->get_username ();
bool write = access_bible::book_write (webserver_request, user, bible, book);
data = checksum_logic::send (data, write);

Expand Down
2 changes: 1 addition & 1 deletion editone2/save.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ std::string editone2_save (Webserver_Request& webserver_request)


// Collect some data about the changes for this user.
std::string username = webserver_request.session_logic()->currentUser ();
const std::string& username = webserver_request.session_logic ()->get_username ();
#ifdef HAVE_CLOUD
int oldID = database::bibles::get_chapter_id (bible, book, chapter);
#endif
Expand Down
2 changes: 1 addition & 1 deletion editone2/update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ std::string editone2_update (Webserver_Request& webserver_request)


// Collect some data about the changes for this user.
std::string username = webserver_request.session_logic()->currentUser ();
const std::string& username = webserver_request.session_logic ()->get_username ();
#ifdef HAVE_CLOUD
int oldID = 0;
if (good2go) oldID = database::bibles::get_chapter_id (bible, book, chapter);
Expand Down
2 changes: 1 addition & 1 deletion editusfm/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ bool editusfm_index_acl (Webserver_Request& webserver_request)

std::string editusfm_index (Webserver_Request& webserver_request)
{
const bool touch = webserver_request.session_logic ()->touchEnabled ();
const bool touch = webserver_request.session_logic ()->get_touch_enabled ();


if (webserver_request.query.count ("switchbook") && webserver_request.query.count ("switchchapter")) {
Expand Down
Loading

0 comments on commit baafcef

Please sign in to comment.