Browse Source

More improvements to prevent the hiding of permission checks

MOODLE_29_STABLE
Dan Marsden 10 years ago
parent
commit
452d483f65
  1. 27
      locallib.php
  2. 20
      renderables.php

27
locallib.php

@ -42,9 +42,6 @@ class attendance_permissions {
private $cantake; private $cantake;
private $canchange; private $canchange;
private $canmanage; private $canmanage;
private $canmanagetemp; // Can manage temporary users.
private $canchangepreferences;
private $canexport;
private $canaccessallgroups; private $canaccessallgroups;
private $cm; private $cm;
@ -92,30 +89,6 @@ class attendance_permissions {
return $this->canmanage; return $this->canmanage;
} }
// Check to see if the user can manage temporary users.
public function can_managetemp() {
if (is_null($this->canmanagetemp)) {
$this->canmanagetemp = has_capability('mod/attendance:managetemporaryusers', $this->context);
}
return $this->canmanagetemp;
}
public function can_change_preferences() {
if (is_null($this->canchangepreferences)) {
$this->canchangepreferences = has_capability('mod/attendance:changepreferences', $this->context);
}
return $this->canchangepreferences;
}
public function can_export() {
if (is_null($this->canexport)) {
$this->canexport = has_capability('mod/attendance:export', $this->context);
}
return $this->canexport;
}
public function can_access_all_groups() { public function can_access_all_groups() {
if (is_null($this->canaccessallgroups)) { if (is_null($this->canaccessallgroups)) {

20
renderables.php

@ -66,14 +66,18 @@ class attendance_tabs implements renderable {
*/ */
public function get_tabs() { public function get_tabs() {
$toprow = array(); $toprow = array();
if ($this->att->perm->can_manage() or
$this->att->perm->can_take() or $capabilities = array(
$this->att->perm->can_change()) { 'mod/attendance:manageattendances',
'mod/attendance:takeattendances',
'mod/attendance:changeattendances'
);
if (has_any_capability($capabilities, $this->att->context)) {
$toprow[] = new tabobject(self::TAB_SESSIONS, $this->att->url_manage()->out(), $toprow[] = new tabobject(self::TAB_SESSIONS, $this->att->url_manage()->out(),
get_string('sessions', 'attendance')); get_string('sessions', 'attendance'));
} }
if ($this->att->perm->can_manage()) { if (has_capability('mod/attendance:manageattendances', $this->att->context)) {
$toprow[] = new tabobject(self::TAB_ADD, $toprow[] = new tabobject(self::TAB_ADD,
$this->att->url_sessions()->out(true, array('action' => att_sessions_page_params::ACTION_ADD)), $this->att->url_sessions()->out(true, array('action' => att_sessions_page_params::ACTION_ADD)),
get_string('add', 'attendance')); get_string('add', 'attendance'));
@ -83,16 +87,16 @@ class attendance_tabs implements renderable {
get_string('report', 'attendance')); get_string('report', 'attendance'));
} }
if ($this->att->perm->can_export()) { if (has_capability('mod/attendance:export', $this->att->context)) {
$toprow[] = new tabobject(self::TAB_EXPORT, $this->att->url_export()->out(), $toprow[] = new tabobject(self::TAB_EXPORT, $this->att->url_export()->out(),
get_string('export', 'attendance')); get_string('export', 'attendance'));
} }
if ($this->att->perm->can_change_preferences()) { if (has_capability('mod/attendance:changepreferences', $this->att->context)) {
$toprow[] = new tabobject(self::TAB_PREFERENCES, $this->att->url_preferences()->out(), $toprow[] = new tabobject(self::TAB_PREFERENCES, $this->att->url_preferences()->out(),
get_string('settings', 'attendance')); get_string('settings', 'attendance'));
} }
if ($this->att->perm->can_managetemp()) { if (has_capability('mod/attendance:managetemporaryusers', $this->att->context)) {
$toprow[] = new tabobject(self::TAB_TEMPORARYUSERS, $this->att->url_managetemp()->out(), $toprow[] = new tabobject(self::TAB_TEMPORARYUSERS, $this->att->url_managetemp()->out(),
get_string('tempusers', 'attendance')); get_string('tempusers', 'attendance'));
} }

Loading…
Cancel
Save