Commit 001f9c41 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Let can_view_view take a View object



Avoids double queries on view/view.php and view/artefact.php, where a
View object is constructed from an id inside can_view_view, and again
on the page.

Change-Id: I0f034f04765f73d64758b6ff7ec11c5cbdcdb6f7
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent 9ef2afd8
......@@ -1754,13 +1754,13 @@ function pieform_template_dir($file, $pluginlocation='') {
* Given a view id, and a user id (defaults to currently logged in user if not
* specified) will return wether this user is allowed to look at this view.
*
* @param integer $view_id View ID to check
* @param mixed $view viewid or View to check
* @param integer $user_id User trying to look at the view (defaults to
* currently logged in user, or null if user isn't logged in)
*
* @returns boolean Wether the specified user can look at the specified view.
*/
function can_view_view($view_id, $user_id=null) {
function can_view_view($view, $user_id=null) {
global $USER, $SESSION;
if (defined('BULKEXPORT')) {
......@@ -1791,8 +1791,15 @@ function can_view_view($view_id, $user_id=null) {
return false;
}
require_once(get_config('libroot') . 'view.php');
$view = new View($view_id);
if (!class_exists('View')) {
require_once(get_config('libroot') . 'view.php');
}
if ($view instanceof View) {
$view_id = $view->get('id');
}
else {
$view = new View($view_id = $view);
}
// group views and logged in users are not affected by
// the institution level config for public views
......
......@@ -40,7 +40,7 @@ $viewid = param_integer('view');
$path = param_variable('path', null);
$view = new View($viewid);
if (!can_view_view($viewid)) {
if (!can_view_view($view)) {
throw new AccessDeniedException();
}
......
......@@ -76,7 +76,11 @@ if (!$showmore) {
$showmore = 0;
}
if (!can_view_view($viewid)) {
if (!isset($view)) {
$view = new View($viewid);
}
if (!can_view_view($view)) {
throw new AccessDeniedException(get_string('accessdenied', 'error'));
}
......@@ -85,10 +89,6 @@ $limit = param_integer('limit', 10);
$offset = param_integer('offset', 0);
$showcomment = param_integer('showcomment', null);
if (!isset($view)) {
$view = new View($viewid);
}
// Create the "make feedback private form" now if it's been submitted
if (param_variable('make_public_submit', null)) {
pieform(ArtefactTypeComment::make_public_form(param_integer('comment')));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment