Skip to content

Commit

Permalink
Clearer types in code rather than void pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
teusbenschop committed Jan 6, 2024
1 parent 8831aa4 commit 0f87a7f
Show file tree
Hide file tree
Showing 23 changed files with 50 additions and 52 deletions.
30 changes: 13 additions & 17 deletions access/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ int view_resources_role ()
}


bool privilege_view_resources (void * webserver_request, string user)
bool privilege_view_resources (Webserver_Request& webserver_request, string user)
{
int level {0};
user_level (webserver_request, user, level);
Expand All @@ -50,7 +50,7 @@ int view_notes_role ()
}


bool privilege_view_notes (void * webserver_request, string user)
bool privilege_view_notes (Webserver_Request& webserver_request, string user)
{
int level {0};
user_level (webserver_request, user, level);
Expand All @@ -65,7 +65,7 @@ int create_comment_notes_role ()
}


bool privilege_create_comment_notes (void * webserver_request, string user)
bool privilege_create_comment_notes (Webserver_Request& webserver_request, string user)
{
int level {0};
user_level (webserver_request, user, level);
Expand All @@ -80,13 +80,12 @@ int delete_consultation_notes_role ()
}


bool privilege_delete_consultation_notes (void * webserver_request, string user)
bool privilege_delete_consultation_notes (Webserver_Request& webserver_request, string user)
{
int level {0};
user_level (webserver_request, user, level);
if (level >= delete_consultation_notes_role ()) return true;
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);
return request->database_config_user ()->getPrivilegeDeleteConsultationNotesForUser (user);
return webserver_request.database_config_user ()->getPrivilegeDeleteConsultationNotesForUser (user);
}


Expand All @@ -96,13 +95,12 @@ int use_advanced_mode_role ()
}


bool privilege_use_advanced_mode (void * webserver_request, string user)
bool privilege_use_advanced_mode (Webserver_Request& webserver_request, string user)
{
int level {0};
user_level (webserver_request, user, level);
if (level >= use_advanced_mode_role ()) return true;
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);
return request->database_config_user ()->getPrivilegeUseAdvancedModeForUser (user);
return webserver_request.database_config_user ()->getPrivilegeUseAdvancedModeForUser (user);
}


Expand All @@ -112,26 +110,24 @@ int set_stylesheets_role ()
}


bool privilege_set_stylesheets (void * webserver_request, string user)
bool privilege_set_stylesheets (Webserver_Request& webserver_request, string user)
{
int level {0};
user_level (webserver_request, user, level);
if (level >= set_stylesheets_role ()) return true;
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);
return request->database_config_user ()->getPrivilegeSetStylesheetsForUser (user);
return webserver_request.database_config_user ()->getPrivilegeSetStylesheetsForUser (user);
}


void user_level (void * webserver_request, string & user, int & level)
void user_level (Webserver_Request& webserver_request, string & user, int & level)
{
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);
if (user.empty ()) {
// If no user is given, take the user from the session.
user = request->session_logic ()->currentUser ();
level = request->session_logic ()->currentLevel ();
user = webserver_request.session_logic ()->currentUser ();
level = webserver_request.session_logic ()->currentLevel ();
} else {
// If a user is given, take the matching level from the database.
level = request->database_users ()->get_level (user);
level = webserver_request.database_users ()->get_level (user);
}
}

Expand Down
16 changes: 9 additions & 7 deletions access/logic.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,33 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

#include <config/libraries.h>

class Webserver_Request;

#define PRIVILEGE_VIEW_RESOURCES 1

namespace access_logic {

int view_resources_role ();
bool privilege_view_resources (void * webserver_request, std::string user = std::string());
bool privilege_view_resources (Webserver_Request& webserver_request, std::string user = std::string());

#define PRIVILEGE_VIEW_NOTES 2
int view_notes_role ();
bool privilege_view_notes (void * webserver_request, std::string user = std::string());
bool privilege_view_notes (Webserver_Request& webserver_request, std::string user = std::string());

#define PRIVILEGE_CREATE_COMMENT_NOTES 3
int create_comment_notes_role ();
bool privilege_create_comment_notes (void * webserver_request, std::string user = std::string());
bool privilege_create_comment_notes (Webserver_Request& webserver_request, std::string user = std::string());

int delete_consultation_notes_role ();
bool privilege_delete_consultation_notes (void * webserver_request, std::string user = std::string());
bool privilege_delete_consultation_notes (Webserver_Request& webserver_request, std::string user = std::string());

int use_advanced_mode_role ();
bool privilege_use_advanced_mode (void * webserver_request, std::string user = std::string());
bool privilege_use_advanced_mode (Webserver_Request& webserver_request, std::string user = std::string());

int set_stylesheets_role ();
bool privilege_set_stylesheets (void * webserver_request, std::string user = std::string());
bool privilege_set_stylesheets (Webserver_Request& webserver_request, std::string user = std::string());

void user_level (void * webserver_request, std::string& user, int& level);
void user_level (Webserver_Request& webserver_request, std::string& user, int& level);
void create_client_files ();

std::set <std::string> default_privilege_usernames ();
Expand Down
2 changes: 1 addition & 1 deletion bb/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,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 ();
bool privilege_stylesheet = access_logic::privilege_set_stylesheets (std::addressof(webserver_request), current_user);
bool privilege_stylesheet = access_logic::privilege_set_stylesheets (webserver_request, current_user);
if (privilege_stylesheet) view.enable_zone ("privilege_stylesheet");


Expand Down
12 changes: 6 additions & 6 deletions manage/privileges.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ string manage_privileges (Webserver_Request& webserver_request)
if (user.empty()) user = webserver_request.post["val1"];
view.set_variable ("user", user);
int level {0};
access_logic::user_level (std::addressof(webserver_request), user, level);
access_logic::user_level (webserver_request, user, level);


// Usernames for setting default new user privilege.
Expand Down Expand Up @@ -96,7 +96,7 @@ string manage_privileges (Webserver_Request& webserver_request)
if (level >= access_logic::view_resources_role () && defusers.find (user) == defusers.end ()) {
view.set_variable ("viewnotesdisabled", filter::strings::get_disabled (true));
}
state = access_logic::privilege_view_notes (std::addressof(webserver_request), user);
state = access_logic::privilege_view_notes (webserver_request, user);
view.set_variable ("viewnoteschecked", filter::strings::get_checkbox_status (state));


Expand All @@ -109,7 +109,7 @@ string manage_privileges (Webserver_Request& webserver_request)
if (level >= access_logic::view_resources_role () && defusers.find (user) == defusers.end ()) {
view.set_variable ("createcommentnotesdisabled", filter::strings::get_disabled (true));
}
state = access_logic::privilege_create_comment_notes (std::addressof(webserver_request), user);
state = access_logic::privilege_create_comment_notes (webserver_request, user);
view.set_variable ("createcommentnoteschecked", filter::strings::get_checkbox_status (state));


Expand All @@ -121,7 +121,7 @@ string manage_privileges (Webserver_Request& webserver_request)
if (level >= access_logic::delete_consultation_notes_role () && defusers.find (user) == defusers.end ()) {
view.set_variable ("deletenotesdisabled", filter::strings::get_disabled (true));
}
state = access_logic::privilege_delete_consultation_notes (std::addressof(webserver_request), user);
state = access_logic::privilege_delete_consultation_notes (webserver_request, user);
view.set_variable ("deletenoteschecked", filter::strings::get_checkbox_status (state));


Expand All @@ -132,7 +132,7 @@ string manage_privileges (Webserver_Request& webserver_request)
if (level >= access_logic::use_advanced_mode_role () && defusers.find (user) == defusers.end ()) {
view.set_variable ("useadvancedmodedisabled", filter::strings::get_disabled (true));
}
state = access_logic::privilege_use_advanced_mode (std::addressof(webserver_request), user);
state = access_logic::privilege_use_advanced_mode (webserver_request, user);
view.set_variable ("useadvancedmodechecked", filter::strings::get_checkbox_status (state));


Expand All @@ -143,7 +143,7 @@ string manage_privileges (Webserver_Request& webserver_request)
if (level >= access_logic::set_stylesheets_role () && defusers.find (user) == defusers.end ()) {
view.set_variable ("editstylesheetsdisabled", filter::strings::get_disabled (true));
}
state = access_logic::privilege_set_stylesheets (std::addressof(webserver_request), user);
state = access_logic::privilege_set_stylesheets (webserver_request, user);
view.set_variable ("editstylesheetschecked", filter::strings::get_checkbox_status (state));


Expand Down
2 changes: 1 addition & 1 deletion notes/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ string notes_actions (Webserver_Request& webserver_request)
if (level >= Filter_Roles::manager ()) view.enable_zone ("rawedit");


if (access_logic::privilege_delete_consultation_notes (std::addressof(webserver_request)))
if (access_logic::privilege_delete_consultation_notes (webserver_request))
view.enable_zone ("deletenote");
bool marked = database_notes.is_marked_for_deletion (id);
if (marked) view.enable_zone ("marked");
Expand Down
2 changes: 1 addition & 1 deletion notes/comment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ string notes_comment_url ()

bool notes_comment_acl (Webserver_Request& webserver_request)
{
return access_logic::privilege_create_comment_notes (std::addressof(webserver_request));
return access_logic::privilege_create_comment_notes (webserver_request);
}


Expand Down
2 changes: 1 addition & 1 deletion notes/create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ string notes_create_url ()

bool notes_create_acl (Webserver_Request& webserver_request)
{
return access_logic::privilege_create_comment_notes (std::addressof(webserver_request));
return access_logic::privilege_create_comment_notes (webserver_request);
}


Expand Down
4 changes: 2 additions & 2 deletions notes/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ string notes_index_url ()

bool notes_index_acl (Webserver_Request& webserver_request)
{
return access_logic::privilege_view_notes (std::addressof(webserver_request));
return access_logic::privilege_view_notes (webserver_request);
}


Expand Down Expand Up @@ -99,7 +99,7 @@ string notes_index (Webserver_Request& webserver_request)
}

// Whether the user can create a new note.
if (access_logic::privilege_create_comment_notes (std::addressof(webserver_request))) {
if (access_logic::privilege_create_comment_notes (webserver_request)) {
view.enable_zone ("create");
}

Expand Down
4 changes: 2 additions & 2 deletions notes/note.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ string notes_note_url ()

bool notes_note_acl (Webserver_Request& webserver_request)
{
return access_logic::privilege_view_notes (std::addressof(webserver_request));
return access_logic::privilege_view_notes (webserver_request);
}


Expand Down Expand Up @@ -140,7 +140,7 @@ string notes_note (Webserver_Request& webserver_request)
if (Filter_Roles::access_control (webserver_request, Filter_Roles::consultant ())) {
view.enable_zone ("consultant");
}
if (access_logic::privilege_create_comment_notes (std::addressof(webserver_request))) {
if (access_logic::privilege_create_comment_notes (webserver_request)) {
view.enable_zone ("comment");
}

Expand Down
2 changes: 1 addition & 1 deletion notes/notes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ string notes_notes_url ()

bool notes_notes_acl (Webserver_Request& webserver_request)
{
return access_logic::privilege_view_notes (std::addressof(webserver_request));
return access_logic::privilege_view_notes (webserver_request);
}


Expand Down
2 changes: 1 addition & 1 deletion notes/poll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ string notes_poll_url ()

bool notes_poll_acl (Webserver_Request& webserver_request)
{
return access_logic::privilege_view_notes (std::addressof(webserver_request));
return access_logic::privilege_view_notes (webserver_request);
}


Expand Down
2 changes: 1 addition & 1 deletion notes/select.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ string notes_select_url ()

bool notes_select_acl (Webserver_Request& webserver_request)
{
return access_logic::privilege_view_notes (std::addressof(webserver_request));
return access_logic::privilege_view_notes (webserver_request);
}


Expand Down
2 changes: 1 addition & 1 deletion personalize/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ string personalize_index (Webserver_Request& webserver_request)


// Enable the sections with settings relevant to the user and device.
bool resources = access_logic::privilege_view_resources (std::addressof(webserver_request));
bool resources = access_logic::privilege_view_resources (webserver_request);
if (resources) view.enable_zone ("resources");
bool bibles = Filter_Roles::access_control (webserver_request, Filter_Roles::translator ());
auto [ read, write ] = access_bible::any (webserver_request);
Expand Down
2 changes: 1 addition & 1 deletion resource/comparative1edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ string resource_comparative1edit_url ()

bool resource_comparative1edit_acl (Webserver_Request& webserver_request)
{
return access_logic::privilege_view_resources (std::addressof(webserver_request));
return access_logic::privilege_view_resources (webserver_request);
}


Expand Down
2 changes: 1 addition & 1 deletion resource/get.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ string resource_get_url ()

bool resource_get_acl (Webserver_Request& webserver_request)
{
return access_logic::privilege_view_resources (std::addressof(webserver_request));
return access_logic::privilege_view_resources (webserver_request);
}


Expand Down
2 changes: 1 addition & 1 deletion resource/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ string resource_index_url ()

bool resource_index_acl (Webserver_Request& webserver_request)
{
return access_logic::privilege_view_resources (std::addressof(webserver_request));
return access_logic::privilege_view_resources (webserver_request);
}


Expand Down
2 changes: 1 addition & 1 deletion resource/organize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ string resource_organize_url ()

bool resource_organize_acl (Webserver_Request& webserver_request)
{
return access_logic::privilege_view_resources (std::addressof(webserver_request));
return access_logic::privilege_view_resources (webserver_request);
}


Expand Down
2 changes: 1 addition & 1 deletion resource/select.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ string resource_select_url ()

bool resource_select_acl (Webserver_Request& webserver_request)
{
return access_logic::privilege_view_resources (std::addressof(webserver_request));
return access_logic::privilege_view_resources (webserver_request);
}


Expand Down
2 changes: 1 addition & 1 deletion resource/translated1edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ string resource_translated1edit_url ()

bool resource_translated1edit_acl (Webserver_Request& webserver_request)
{
return access_logic::privilege_view_resources (std::addressof(webserver_request));
return access_logic::privilege_view_resources (webserver_request);
}


Expand Down
2 changes: 1 addition & 1 deletion resource/unload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ string resource_unload_url ()

bool resource_unload_acl (Webserver_Request& webserver_request)
{
return access_logic::privilege_view_resources (std::addressof(webserver_request));
return access_logic::privilege_view_resources (webserver_request);
}


Expand Down
2 changes: 1 addition & 1 deletion resource/user1view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ string resource_user1view_url ()

bool resource_user1view_acl (Webserver_Request& webserver_request)
{
return access_logic::privilege_view_resources (std::addressof(webserver_request));
return access_logic::privilege_view_resources (webserver_request);
}


Expand Down
2 changes: 1 addition & 1 deletion resource/user9view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ string resource_user9view_url ()

bool resource_user9view_acl (Webserver_Request& webserver_request)
{
return access_logic::privilege_view_resources (std::addressof(webserver_request));
return access_logic::privilege_view_resources (webserver_request);
}


Expand Down
2 changes: 1 addition & 1 deletion user/notifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ bool user_notifications_acl (Webserver_Request& webserver_request)
if (Filter_Roles::access_control (webserver_request, Filter_Roles::consultant ()))
return true;
// Whoever can view notes has access.
if (access_logic::privilege_view_notes (std::addressof(webserver_request)))
if (access_logic::privilege_view_notes (webserver_request))
return true;
// Whoever has access to a Bible has access to this page.
auto [ read, write ] = access_bible::any (webserver_request);
Expand Down

0 comments on commit 0f87a7f

Please sign in to comment.