Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return 404 if project page table doesn't exist #1178

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions api/v1_projects.inc
Original file line number Diff line number Diff line change
Expand Up @@ -436,12 +436,16 @@ function api_v1_project_pages($method, $data, $query_params)
$project = $data[":projectid"];

$return_data = [];
foreach ($project->get_page_names_from_db() as $image) {
$return_data[] = [
"image" => $image,
"image_url" => "{$project->url}/$image",
"image_size" => (int)$project->get_image_file_size($image),
];
try {
foreach ($project->get_page_names_from_db() as $image) {
$return_data[] = [
"image" => $image,
"image_url" => "{$project->url}/$image",
"image_size" => (int)$project->get_image_file_size($image),
];
}
} catch (NoProjectPageTable $exception) {
throw new NotFoundError($exception->getMessage(), $exception->getCode());
}
return $return_data;
}
Expand Down Expand Up @@ -470,7 +474,11 @@ function api_v1_project_pagedetails($method, $data, $query_params)
}

$project = $data[":projectid"];
$rounds_to_display = get_rounds_to_display($project);
try {
$rounds_to_display = get_rounds_to_display($project);
} catch (NoProjectPageTable $exception) {
throw new NotFoundError($exception->getMessage(), $exception->getCode());
}
if (!is_null($only_rounds)) {
$rounds_to_display = array_intersect($rounds_to_display, $only_rounds);
}
Expand Down
2 changes: 1 addition & 1 deletion api/v1_validators.inc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function validate_page_name($pagename, $data)
throw new NonexistentPageException("No such page in project");
}
return $pagename;
} catch (NonexistentPageException $exception) {
} catch (NonexistentPageException | NoProjectPageTable $exception) {
throw new NotFoundError($exception->getMessage(), $exception->getCode());
}
}
Expand Down
11 changes: 8 additions & 3 deletions pinc/page_table.inc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function get_rounds_to_display($project)
// yet to do, so there may be some round-columns with no data in them.
// Figure out which ones to display.
//
$rounds_to_display = get_rounds_with_data($project->projectid);
$rounds_to_display = get_rounds_with_data($project);

// If the project is in a round, then users expect that round to appear here,
// even if there's no data in it.
Expand Down Expand Up @@ -132,7 +132,7 @@ function fetch_page_table_data($project, $page_selector = null, $work_round = nu
$wordcheck_events = [];
}

$rounds_with_data = get_rounds_with_data($project->projectid);
$rounds_with_data = get_rounds_with_data($project);

$fields_to_get = "{$project->projectid}.image AS image, length(master_text), state";
$tables = $project->projectid;
Expand Down Expand Up @@ -560,8 +560,13 @@ function can_user_see_usernames_for_page(Project $project, array $proofer_userna
* Returns an array of Rounds representing those rounds
* for which the given project has some useful data.
*/
function get_rounds_with_data($projectid)
function get_rounds_with_data(Project $project): array
{
$projectid = $project->projectid;
if (!$project->pages_table_exists) {
throw new NoProjectPageTable(_("Project page table does not exist."));
}

$rounds_with_data = [];

// Currently, when a project skips a round, the time and text of the
Expand Down