Skip to content

Commit

Permalink
Better typing
Browse files Browse the repository at this point in the history
  • Loading branch information
teusbenschop committed Dec 31, 2023
1 parent 9f7d42d commit 51e414a
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 50 deletions.
8 changes: 4 additions & 4 deletions bootstrap/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,13 +432,13 @@ void bootstrap_index (Webserver_Request& webserver_request)
return;
}

if ((url == resource_bible2resource_url ()) && browser_request_security_okay (webserver_request) && resource_bible2resource_acl (std::addressof(webserver_request))) {
webserver_request.reply = resource_bible2resource (std::addressof(webserver_request));
if ((url == resource_bible2resource_url ()) && browser_request_security_okay (webserver_request) && resource_bible2resource_acl (webserver_request)) {
webserver_request.reply = resource_bible2resource (webserver_request);
return;
}

if ((url == checks_index_url ()) && browser_request_security_okay (webserver_request) && checks_index_acl (std::addressof(webserver_request))) {
webserver_request.reply = checks_index (std::addressof(webserver_request));
if ((url == checks_index_url ()) && browser_request_security_okay (webserver_request) && checks_index_acl (webserver_request)) {
webserver_request.reply = checks_index (webserver_request);
return;
}

Expand Down
46 changes: 22 additions & 24 deletions checks/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,72 +34,70 @@
#include <access/bible.h>
#include <menu/logic.h>
#include <checks/settings.h>
using namespace std;


string checks_index_url ()
std::string checks_index_url ()
{
return "checks/index";
}


bool checks_index_acl (void * webserver_request)
bool checks_index_acl (Webserver_Request& webserver_request)
{
return Filter_Roles::access_control (webserver_request, Filter_Roles::translator ());
return Filter_Roles::access_control (std::addressof(webserver_request), Filter_Roles::translator ());
}


string checks_index (void * webserver_request)
std::string checks_index (Webserver_Request& webserver_request)
{
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);
Database_Check database_check {};


string page {};
Assets_Header header = Assets_Header (translate("Checks"), webserver_request);
std::string page {};
Assets_Header header = Assets_Header (translate("Checks"), std::addressof(webserver_request));
header.add_bread_crumb (menu_logic_tools_menu (), menu_logic_tools_text ());
page = header.run ();
Assets_View view {};


if (request->query.count ("approve")) {
int approve = filter::strings::convert_to_int (request->query["approve"]);
if (webserver_request.query.count ("approve")) {
const int approve = filter::strings::convert_to_int (webserver_request.query["approve"]);
database_check.approve (approve);
view.set_variable ("success", translate("The entry was suppressed."));
}


if (request->query.count ("delete")) {
int erase = filter::strings::convert_to_int (request->query["delete"]);
if (webserver_request.query.count ("delete")) {
const int erase = filter::strings::convert_to_int (webserver_request.query["delete"]);
database_check.erase (erase);
view.set_variable ("success", translate("The entry was deleted for just now."));
}


// Get the Bibles the user has write-access to.
vector <string> bibles {};
std::vector <std::string> bibles {};
{
const vector <string> & all_bibles = request->database_bibles()->get_bibles ();
for (const auto & bible : all_bibles) {
if (access_bible::write (webserver_request, bible)) {
const std::vector <std::string>& all_bibles = webserver_request.database_bibles()->get_bibles ();
for (const auto& bible : all_bibles) {
if (access_bible::write (std::addressof(webserver_request), bible)) {
bibles.push_back (bible);
}
}
}


stringstream resultblock {};
const vector <Database_Check_Hit> & hits = database_check.getHits ();
for (const auto & hit : hits) {
string bible = hit.bible;
std::stringstream resultblock {};
const std::vector <Database_Check_Hit>& hits = database_check.getHits ();
for (const auto& hit : hits) {
std::string bible = hit.bible;
if (find (bibles.begin(), bibles.end (), bible) != bibles.end ()) {
int id = hit.rowid;
const int id = hit.rowid;
bible = filter::strings::escape_special_xml_characters (bible);
int book = hit.book;
int chapter = hit.chapter;
int verse = hit.verse;
string link = filter_passage_link_for_opening_editor_at (book, chapter, filter::strings::convert_to_string (verse));
string information = filter::strings::escape_special_xml_characters (hit.data);
const std::string link = filter_passage_link_for_opening_editor_at (book, chapter, filter::strings::convert_to_string (verse));
const std::string information = filter::strings::escape_special_xml_characters (hit.data);
resultblock << "<p>\n";
resultblock << "<a href=" << quoted("index?approve=" + filter::strings::convert_to_string (id)) << "> ✔ </a>\n";
resultblock << "<a href=" << quoted ("index?delete=" + filter::strings::convert_to_string (id)) << ">" << filter::strings::emoji_wastebasket () << "</a>\n";
Expand All @@ -114,7 +112,7 @@ string checks_index (void * webserver_request)
view.set_variable ("resultblock", resultblock.str());


if (checks_settings_acl (webserver_request)) {
if (checks_settings_acl (std::addressof(webserver_request))) {
view.enable_zone ("can_enable");
} else {
view.enable_zone ("cannot_enable");
Expand Down
4 changes: 2 additions & 2 deletions checks/index.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
class Webserver_Request;

std::string checks_index_url ();
bool checks_index_acl (void * webserver_request);
std::string checks_index (void * webserver_request);
bool checks_index_acl (Webserver_Request& webserver_request);
std::string checks_index (Webserver_Request& webserver_request);
4 changes: 3 additions & 1 deletion menu/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,8 @@ string menu_logic_search_category (void * webserver_request, string * tooltip)

string menu_logic_tools_category (void * webserver_request, string * tooltip)
{
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);

// The labels that may end up in the menu.
string checks = translate ("Checks");
string consistency = translate ("Consistency");
Expand Down Expand Up @@ -575,7 +577,7 @@ string menu_logic_tools_category (void * webserver_request, string * tooltip)
for (auto & label : labels) {

if (label == checks) {
if (checks_index_acl (webserver_request)) {
if (checks_index_acl (*request)) {
html.push_back (menu_logic_create_item (checks_index_url (), label, true, "", ""));
tiplabels.push_back (label);
}
Expand Down
32 changes: 15 additions & 17 deletions resource/bb2resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,54 +34,52 @@
#include <resource/external.h>
#include <menu/logic.h>
#include <bb/manage.h>
using namespace std;


string resource_bible2resource_url ()
std::string resource_bible2resource_url ()
{
return "resource/bb2resource";
}


bool resource_bible2resource_acl (void * webserver_request)
bool resource_bible2resource_acl (Webserver_Request& webserver_request)
{
return Filter_Roles::access_control (webserver_request, Filter_Roles::manager ());
return Filter_Roles::access_control (std::addressof(webserver_request), Filter_Roles::manager ());
}


string resource_bible2resource (void * webserver_request)
std::string resource_bible2resource (Webserver_Request& webserver_request)
{
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);
Database_UsfmResources database_usfmresources = Database_UsfmResources ();


string page;
Assets_Header header = Assets_Header (translate("Convert"), request);
std::string page;
Assets_Header header = Assets_Header (translate("Convert"), std::addressof(webserver_request));
header.add_bread_crumb (menu_logic_settings_menu (), menu_logic_settings_text ());
header.add_bread_crumb (bible_manage_url (), menu_logic_bible_manage_text ());
page = header.run ();
Assets_View view;


string bible = request->query["bible"];
const std::string bible = webserver_request.query["bible"];
view.set_variable ("bible", bible);


vector <string> usfmResources = database_usfmresources.getResources ();
if (find (usfmResources.begin(), usfmResources.end (), bible) != usfmResources.end ()) {
const std::vector <std::string> usfm_resources = database_usfmresources.getResources ();
if (find (usfm_resources.begin(), usfm_resources.end (), bible) != usfm_resources.end ()) {
view.set_variable ("error", translate("A USFM Resource with this name already exists"));
}
vector <string> externalResources = resource_external_names ();
if (find (externalResources.begin(), externalResources.end (), bible) != externalResources.end ()) {
const std::vector <std::string> external_resources = resource_external_names ();
if (find (external_resources.begin(), external_resources.end (), bible) != external_resources.end ()) {
view.set_variable ("error", translate("An external resource with this name already exists"));
}


if (request->query.count ("convert")) {
if (access_bible::write (request, bible)) {
if (webserver_request.query.count ("convert")) {
if (access_bible::write (std::addressof(webserver_request), bible)) {
tasks_logic_queue (CONVERTBIBLE2RESOURCE, {bible});
redirect_browser (request, journal_index_url ());
return "";
redirect_browser (std::addressof(webserver_request), journal_index_url ());
return std::string();
} else {
assets_page::error (translate("Insufficient privileges to complete operation."));
}
Expand Down
4 changes: 2 additions & 2 deletions resource/bb2resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
class Webserver_Request;

std::string resource_bible2resource_url ();
bool resource_bible2resource_acl (void * webserver_request);
std::string resource_bible2resource (void * webserver_request);
bool resource_bible2resource_acl (Webserver_Request& webserver_request);
std::string resource_bible2resource (Webserver_Request& webserver_request);

0 comments on commit 51e414a

Please sign in to comment.