Skip to content

Commit

Permalink
Make std namespace clearer
Browse files Browse the repository at this point in the history
  • Loading branch information
teusbenschop committed Mar 30, 2024
1 parent 36314c0 commit 9833265
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 35 deletions.
35 changes: 17 additions & 18 deletions access/bible.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include <database/privileges.h>
#include <client/logic.h>
#include <filter/roles.h>
using namespace std;


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
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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.
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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.
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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 <string> bibles (Webserver_Request& webserver_request, string user)
std::vector <std::string> bibles (Webserver_Request& webserver_request, std::string user)
{
vector <string> allbibles = webserver_request.database_bibles()->get_bibles ();
vector <string> bibles;
for (auto & bible : allbibles) {
std::vector <std::string> allbibles = webserver_request.database_bibles()->get_bibles ();
std::vector <std::string> bibles {};
for (const auto& bible : allbibles) {
if (read (webserver_request, bible, user)) {
bibles.push_back (bible);
}
Expand All @@ -192,11 +191,11 @@ vector <string> 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 <string> bibles = access_bible::bibles (webserver_request);
bible = std::string();
std::vector <std::string> bibles = access_bible::bibles (webserver_request);
if (!bibles.empty ()) bible = bibles [0];
webserver_request.database_config_user ()->setBible (bible);
}
Expand All @@ -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 <read, write>.
tuple<bool, bool> any (Webserver_Request& webserver_request)
std::tuple<bool, bool> any (Webserver_Request& webserver_request)
{
bool read {false};
bool write {false};
vector <string> bibles = webserver_request.database_bibles()->get_bibles ();
for (auto & bible : bibles) {
std::vector <std::string> 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 <read, write>.
return make_tuple(read, write);
return std::make_tuple(read, write);
}


Expand Down
21 changes: 10 additions & 11 deletions access/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include <filter/roles.h>
#include <database/privileges.h>
#include <webserver/request.h>
using namespace std;


namespace access_logic {
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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.
Expand All @@ -135,16 +134,16 @@ void user_level (Webserver_Request& webserver_request, string & user, int & leve
void create_client_files ()
{
Database_Users database_users;
vector <string> users = database_users.get_users ();
for (auto & user : users) {
std::vector <std::string> 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);
}
}


set <string> default_privilege_usernames ()
std::set <std::string> default_privilege_usernames ()
{
return {"defaultguest", "defaultmember", "defaultconsultant", "defaulttranslator", "defaultmanager"};
}
Expand Down
11 changes: 5 additions & 6 deletions access/user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,21 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include <webserver/request.h>
#include <access/bible.h>
#include <filter/roles.h>
using namespace std;


// This function returns users assigned to the logged-in user.
vector <string> access_user::assignees (Webserver_Request& webserver_request)
std::vector <std::string> 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 <string> assignees {};
std::vector <std::string> assignees {};

// Process all users.
vector <string> users = webserver_request.database_users ()->get_users ();
std::vector <std::string> 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);
Expand Down

0 comments on commit 9833265

Please sign in to comment.