diff --git a/access/bible.cpp b/access/bible.cpp index d7597f58b..6405cd368 100644 --- a/access/bible.cpp +++ b/access/bible.cpp @@ -23,7 +23,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include -using namespace std; namespace access_bible { @@ -31,7 +30,7 @@ namespace access_bible { // Returns true if the $user has read access to the $bible. // If no $user is given, it takes the currently logged-in user. -bool read (Webserver_Request& webserver_request, const string & bible, string user) +bool read (Webserver_Request& webserver_request, const std::string& bible, std::string user) { // Client: User has access to all Bibles. #ifdef HAVE_CLIENT @@ -67,7 +66,7 @@ bool read (Webserver_Request& webserver_request, const string & bible, string us // No Bibles assigned: Consultant can view any Bible. if (role_level >= Filter_Roles::consultant ()) { - if (int privileges_count = DatabasePrivileges::get_bible_book_count (); privileges_count == 0) { + if (const int privileges_count = DatabasePrivileges::get_bible_book_count (); privileges_count == 0) { return true; } } @@ -79,7 +78,7 @@ bool read (Webserver_Request& webserver_request, const string & bible, string us // Returns true if the user has write access to the $bible. -bool write (Webserver_Request& webserver_request, const string & bible, string user) +bool write (Webserver_Request& webserver_request, const std::string& bible, std::string user) { #ifdef HAVE_CLIENT // Client: When not yet connected to the Cloud, the user has access to all Bibles. @@ -113,7 +112,7 @@ bool write (Webserver_Request& webserver_request, const string & bible, string u // No Bibles assigned: Translator can write to any bible. if (level >= Filter_Roles::translator ()) { - if (int privileges_count = DatabasePrivileges::get_bible_book_count (); privileges_count == 0) { + if (const int privileges_count = DatabasePrivileges::get_bible_book_count (); privileges_count == 0) { return true; } } @@ -127,7 +126,7 @@ bool write (Webserver_Request& webserver_request, const string & bible, string u // If no user is given, it takes the currently logged-in user. // If the user has read-only access to even one book of the $bible, // then the user is considered not to have write access to the entire $bible. -bool book_write (Webserver_Request& webserver_request, string user, const string & bible, int book) +bool book_write (Webserver_Request& webserver_request, std::string user, const std::string& bible, int book) { #ifdef HAVE_CLIENT // Client: When not yet connected to the Cloud, the user has access to the book. @@ -164,7 +163,7 @@ bool book_write (Webserver_Request& webserver_request, string user, const string // No Bibles assigned: Translator can write to any bible. if (level >= Filter_Roles::translator ()) { - if (int privileges_count = DatabasePrivileges::get_bible_book_count (); privileges_count == 0) { + if (const int privileges_count = DatabasePrivileges::get_bible_book_count (); privileges_count == 0) { return true; } } @@ -176,11 +175,11 @@ bool book_write (Webserver_Request& webserver_request, string user, const string // Returns an array of Bibles the user has read access to. // If no user is given, it takes the currently logged-in user. -vector bibles (Webserver_Request& webserver_request, string user) +std::vector bibles (Webserver_Request& webserver_request, std::string user) { - vector allbibles = webserver_request.database_bibles()->get_bibles (); - vector bibles; - for (auto & bible : allbibles) { + std::vector allbibles = webserver_request.database_bibles()->get_bibles (); + std::vector bibles {}; + for (const auto& bible : allbibles) { if (read (webserver_request, bible, user)) { bibles.push_back (bible); } @@ -192,11 +191,11 @@ vector bibles (Webserver_Request& webserver_request, string user) // This function clamps bible. // It returns the $bible if the currently logged-in user has access to it. // Else it returns another accessible bible or nothing. -string clamp (Webserver_Request& webserver_request, string bible) +std::string clamp (Webserver_Request& webserver_request, std::string bible) { if (!read (webserver_request, bible)) { - bible = string(); - vector bibles = access_bible::bibles (webserver_request); + bible = std::string(); + std::vector bibles = access_bible::bibles (webserver_request); if (!bibles.empty ()) bible = bibles [0]; webserver_request.database_config_user ()->setBible (bible); } @@ -207,17 +206,17 @@ string clamp (Webserver_Request& webserver_request, string bible) // This function checks whether the user in the $webserver_request // has $read or $write access to one or more Bibles. // It returns a tuple . -tuple any (Webserver_Request& webserver_request) +std::tuple any (Webserver_Request& webserver_request) { bool read {false}; bool write {false}; - vector bibles = webserver_request.database_bibles()->get_bibles (); - for (auto & bible : bibles) { + std::vector bibles = webserver_request.database_bibles()->get_bibles (); + for (const auto& bible : bibles) { if (access_bible::read (webserver_request, bible)) read = true; if (access_bible::write (webserver_request, bible)) write = true; } // The results consists of . - return make_tuple(read, write); + return std::make_tuple(read, write); } diff --git a/access/logic.cpp b/access/logic.cpp index 7a4df2e53..00e90db86 100644 --- a/access/logic.cpp +++ b/access/logic.cpp @@ -23,7 +23,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include -using namespace std; namespace access_logic { @@ -35,7 +34,7 @@ int view_resources_role () } -bool privilege_view_resources (Webserver_Request& webserver_request, string user) +bool privilege_view_resources (Webserver_Request& webserver_request, std::string user) { int level {0}; user_level (webserver_request, user, level); @@ -50,7 +49,7 @@ int view_notes_role () } -bool privilege_view_notes (Webserver_Request& webserver_request, string user) +bool privilege_view_notes (Webserver_Request& webserver_request, std::string user) { int level {0}; user_level (webserver_request, user, level); @@ -65,7 +64,7 @@ int create_comment_notes_role () } -bool privilege_create_comment_notes (Webserver_Request& webserver_request, string user) +bool privilege_create_comment_notes (Webserver_Request& webserver_request, std::string user) { int level {0}; user_level (webserver_request, user, level); @@ -80,7 +79,7 @@ int delete_consultation_notes_role () } -bool privilege_delete_consultation_notes (Webserver_Request& webserver_request, string user) +bool privilege_delete_consultation_notes (Webserver_Request& webserver_request, std::string user) { int level {0}; user_level (webserver_request, user, level); @@ -95,7 +94,7 @@ int use_advanced_mode_role () } -bool privilege_use_advanced_mode (Webserver_Request& webserver_request, string user) +bool privilege_use_advanced_mode (Webserver_Request& webserver_request, std::string user) { int level {0}; user_level (webserver_request, user, level); @@ -110,7 +109,7 @@ int set_stylesheets_role () } -bool privilege_set_stylesheets (Webserver_Request& webserver_request, string user) +bool privilege_set_stylesheets (Webserver_Request& webserver_request, std::string user) { int level {0}; user_level (webserver_request, user, level); @@ -119,7 +118,7 @@ bool privilege_set_stylesheets (Webserver_Request& webserver_request, string use } -void user_level (Webserver_Request& webserver_request, string & user, int & level) +void user_level (Webserver_Request& webserver_request, std::string& user, int& level) { if (user.empty ()) { // If no user is given, take the user from the session. @@ -135,8 +134,8 @@ void user_level (Webserver_Request& webserver_request, string & user, int & leve void create_client_files () { Database_Users database_users; - vector users = database_users.get_users (); - for (auto & user : users) { + std::vector users = database_users.get_users (); + for (const auto& user : users) { // Only maintain the privilege file if it does not yet exist, // to avoid unnecessary downloads by the clients. database_privileges_client_create (user, false); @@ -144,7 +143,7 @@ void create_client_files () } -set default_privilege_usernames () +std::set default_privilege_usernames () { return {"defaultguest", "defaultmember", "defaultconsultant", "defaulttranslator", "defaultmanager"}; } diff --git a/access/user.cpp b/access/user.cpp index 82e8eaa15..f89ad0679 100644 --- a/access/user.cpp +++ b/access/user.cpp @@ -21,22 +21,21 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include #include -using namespace std; // This function returns users assigned to the logged-in user. -vector access_user::assignees (Webserver_Request& webserver_request) +std::vector access_user::assignees (Webserver_Request& webserver_request) { - const string myuser = webserver_request.session_logic ()->currentUser (); + const std::string myuser = webserver_request.session_logic ()->currentUser (); const int mylevel = webserver_request.session_logic ()->currentLevel (); // This holds the assignees. - vector assignees {}; + std::vector assignees {}; // Process all users. - vector users = webserver_request.database_users ()->get_users (); + std::vector users = webserver_request.database_users ()->get_users (); sort (users.begin(), users.end()); - for (const auto & user : users) { + for (const auto& user : users) { // Assignees should have a level less than or equal to mylevel. if (webserver_request.database_users ()->get_level (user) <= mylevel) { assignees.push_back (user);